aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/system/op_test.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-23 14:15:13 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-23 14:15:13 +0900
commite35c5fe3ed995d352c001bd7e35bd1214ca583da (patch)
tree27fd84e715670374eb126590a7e918ab7e33dd12 /internal/system/op_test.go
parent20195ece478a28b2bc7abc78cd220f900958eb35 (diff)
system: sys comparison method
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/system/op_test.go')
-rw-r--r--internal/system/op_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/internal/system/op_test.go b/internal/system/op_test.go
index 50f260ad..e1419d0f 100644
--- a/internal/system/op_test.go
+++ b/internal/system/op_test.go
@@ -51,3 +51,79 @@ func TestTypeString(t *testing.T) {
})
}
}
+
+func TestI_Equal(t *testing.T) {
+ testCases := []struct {
+ name string
+ sys *system.I
+ v *system.I
+ want bool
+ }{
+ {
+ "simple UID",
+ system.New(150),
+ system.New(150),
+ true,
+ },
+ {
+ "simple UID differ",
+ system.New(150),
+ system.New(151),
+ false,
+ },
+ {
+ "simple UID nil",
+ system.New(150),
+ nil,
+ false,
+ },
+ {
+ "op length mismatch",
+ system.New(150).
+ ChangeHosts("chronos"),
+ system.New(150).
+ ChangeHosts("chronos").
+ Ensure("/run", 0755),
+ false,
+ },
+ {
+ "op value mismatch",
+ system.New(150).
+ ChangeHosts("chronos").
+ Ensure("/run", 0644),
+ system.New(150).
+ ChangeHosts("chronos").
+ Ensure("/run", 0755),
+ false,
+ },
+ {
+ "op type mismatch",
+ system.New(150).
+ ChangeHosts("chronos").
+ CopyFile("/tmp/fortify.1971/30c9543e0a2c9621a8bfecb9d874c347/pulse-cookie", "/home/ophestra/xdg/config/pulse/cookie"),
+ system.New(150).
+ ChangeHosts("chronos").
+ Ensure("/run", 0755),
+ false,
+ },
+ {
+ "op equals",
+ system.New(150).
+ ChangeHosts("chronos").
+ Ensure("/run", 0755),
+ system.New(150).
+ ChangeHosts("chronos").
+ Ensure("/run", 0755),
+ true,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ if tc.sys.Equal(tc.v) != tc.want {
+ t.Errorf("Equal: got %v; want %v",
+ !tc.want, tc.want)
+ }
+ })
+ }
+}