Skip to content

Commit 2db69c5

Browse files
committed
feat: detect pkg name from policy
1 parent f4aa6b6 commit 2db69c5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

validator/policyeval_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,27 @@ func Test_PolicyEval(t *testing.T) {
4747
})
4848
}
4949
}
50+
51+
func Test_DetectPkgName(t *testing.T) {
52+
tests := []struct {
53+
name string
54+
policy string
55+
want string
56+
}{
57+
{name: "detect pkg name exist", policy: "./fixture/pod_policy_deny", want: "example"},
58+
{name: "detect pkg name not exist", policy: "./fixture/pod_policy_deny_bad", want: ""},
59+
}
60+
for _, tt := range tests {
61+
t.Run(tt.name, func(t *testing.T) {
62+
policy, err := ioutil.ReadFile(tt.policy)
63+
if err != nil {
64+
t.Fatal(err)
65+
}
66+
pe := &policyEval{}
67+
got := pe.detectPkgName(string(policy))
68+
if got != tt.want {
69+
t.Errorf("Test_DetectPkgName() = %v, want %v", got[0], tt.want)
70+
}
71+
})
72+
}
73+
}

0 commit comments

Comments
 (0)