1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/cmd/cli/kubectl-kyverno/exception/load_test.go
gcp-cherry-pick-bot[bot] 84d68ee0f1
feat: add cli package to load policy exceptions (#8508) (#8513)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-22 10:44:52 +00:00

41 lines
1,001 B
Go

package exception
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Load(t *testing.T) {
tests := []struct {
name string
policies string
wantLoaded int
wantErr bool
}{{
name: "not a policy exception",
policies: "../_testdata/resources/namespace.yaml",
wantErr: true,
}, {
name: "policy exception",
policies: "../_testdata/exceptions/exception.yaml",
wantLoaded: 1,
}, {
name: "policy exception and policy",
policies: "../_testdata/exceptions/exception-and-policy.yaml",
wantErr: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bytes, err := os.ReadFile(tt.policies)
require.NoError(t, err)
require.NoError(t, err)
if res, err := Load(bytes); (err != nil) != tt.wantErr {
t.Errorf("Load() error = %v, wantErr %v", err, tt.wantErr)
} else if len(res) != tt.wantLoaded {
t.Errorf("Load() loaded amount = %v, wantLoaded %v", len(res), tt.wantLoaded)
}
})
}
}