aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/system/op_internal_test.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-17 20:28:55 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-17 20:28:55 +0900
commit679e719f9e4d9230482491bf253a0d538f030f08 (patch)
tree4b26de24ea9384dbd5cbf569c924efd2bfdc134c /internal/system/op_internal_test.go
parent064db9f02088448b42758dc089787ca7d05b1510 (diff)
system: tests for all Op implementations except DBus
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/system/op_internal_test.go')
-rw-r--r--internal/system/op_internal_test.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/internal/system/op_internal_test.go b/internal/system/op_internal_test.go
new file mode 100644
index 00000000..7ec4f174
--- /dev/null
+++ b/internal/system/op_internal_test.go
@@ -0,0 +1,79 @@
+package system
+
+import "testing"
+
+type tcOp struct {
+ et Enablement
+ path string
+}
+
+// test an instance of the Op interface
+func (ptc tcOp) test(t *testing.T, gotOps []Op, wantOps []Op, fn string) {
+ if len(gotOps) != len(wantOps) {
+ t.Errorf("%s: inserted %v Ops, want %v", fn,
+ len(gotOps), len(wantOps))
+ return
+ }
+
+ t.Run("path", func(t *testing.T) {
+ if len(gotOps) > 0 {
+ if got := gotOps[0].Path(); got != ptc.path {
+ t.Errorf("Path() = %q, want %q",
+ got, ptc.path)
+ return
+ }
+ }
+ })
+
+ for i := range gotOps {
+ o := gotOps[i]
+
+ t.Run("is", func(t *testing.T) {
+ if !o.Is(o) {
+ t.Errorf("Is returned false on self")
+ return
+ }
+ if !o.Is(wantOps[i]) {
+ t.Errorf("%s: inserted %#v, want %#v",
+ fn,
+ o, wantOps[i])
+ return
+ }
+ })
+
+ t.Run("criteria", func(t *testing.T) {
+ testCases := []struct {
+ name string
+ ec *Criteria
+ want bool
+ }{
+ {"nil", newCriteria(), ptc.et != User},
+ {"self", newCriteria(ptc.et), true},
+ {"all", newCriteria(EWayland, EX11, EDBus, EPulse, User, Process), true},
+ {"enablements", newCriteria(EWayland, EX11, EDBus, EPulse), ptc.et != User && ptc.et != Process},
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := tc.ec.hasType(o); got != tc.want {
+ t.Errorf("hasType: got %v, want %v",
+ got, tc.want)
+ }
+ })
+ }
+ })
+ }
+}
+
+func newCriteria(labels ...Enablement) *Criteria {
+ ec := new(Criteria)
+ if len(labels) == 0 {
+ return ec
+ }
+
+ ec.Enablements = new(Enablements)
+ for _, e := range labels {
+ ec.Set(e)
+ }
+ return ec
+}