diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-10-17 20:28:55 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-10-17 20:28:55 +0900 |
| commit | 679e719f9e4d9230482491bf253a0d538f030f08 (patch) | |
| tree | 4b26de24ea9384dbd5cbf569c924efd2bfdc134c /internal/system/mkdir_test.go | |
| parent | 064db9f02088448b42758dc089787ca7d05b1510 (diff) | |
system: tests for all Op implementations except DBus
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/system/mkdir_test.go')
| -rw-r--r-- | internal/system/mkdir_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/internal/system/mkdir_test.go b/internal/system/mkdir_test.go new file mode 100644 index 00000000..20826940 --- /dev/null +++ b/internal/system/mkdir_test.go @@ -0,0 +1,73 @@ +package system + +import ( + "os" + "testing" +) + +func TestEnsure(t *testing.T) { + testCases := []struct { + name string + perm os.FileMode + }{ + {"/tmp/fortify.1971", 0701}, + {"/tmp/fortify.1971/tmpdir", 0700}, + {"/tmp/fortify.1971/tmpdir/150", 0700}, + {"/run/user/1971/fortify", 0700}, + } + for _, tc := range testCases { + t.Run(tc.name+"_"+tc.perm.String(), func(t *testing.T) { + sys := New(150) + sys.Ensure(tc.name, tc.perm) + (&tcOp{User, tc.name}).test(t, sys.ops, []Op{&Mkdir{User, tc.name, tc.perm, false}}, "Ensure") + }) + } +} + +func TestEphemeral(t *testing.T) { + testCases := []struct { + perm os.FileMode + tcOp + }{ + {0700, tcOp{Process, "/run/user/1971/fortify/ec07546a772a07cde87389afc84ffd13"}}, + {0701, tcOp{Process, "/tmp/fortify.1971/ec07546a772a07cde87389afc84ffd13"}}, + } + for _, tc := range testCases { + t.Run(tc.path+"_"+tc.perm.String()+"_"+TypeString(tc.et), func(t *testing.T) { + sys := New(150) + sys.Ephemeral(tc.et, tc.path, tc.perm) + tc.test(t, sys.ops, []Op{&Mkdir{tc.et, tc.path, tc.perm, true}}, "Ephemeral") + }) + } +} + +func TestMkdir_String(t *testing.T) { + testCases := []struct { + want string + ephemeral bool + et Enablement + }{ + {"Ensure", false, User}, + {"Ensure", false, Process}, + {"Ensure", false, EWayland}, + + {"Wayland", true, EWayland}, + {"X11", true, EX11}, + {"D-Bus", true, EDBus}, + {"PulseAudio", true, EPulse}, + } + for _, tc := range testCases { + t.Run(tc.want, func(t *testing.T) { + m := &Mkdir{ + et: tc.et, + path: "/nonexistent", + perm: 0701, + ephemeral: tc.ephemeral, + } + want := "mode: " + os.FileMode(0701).String() + " type: " + tc.want + " path: \"/nonexistent\"" + if got := m.String(); got != want { + t.Errorf("String() = %v, want %v", got, want) + } + }) + } +} |
