diff --git a/pkg/discovery/discovery_test.go b/pkg/discovery/discovery_test.go index cdc19ea49..e27f49336 100644 --- a/pkg/discovery/discovery_test.go +++ b/pkg/discovery/discovery_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" + "github.com/kyverno/chainsaw/pkg/model" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -22,7 +23,7 @@ func TestDiscoverTests(t *testing.T) { paths: []string{"../../testdata/discovery/test"}, want: []Test{{ BasePath: "../../testdata/discovery/test", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", @@ -68,7 +69,7 @@ func TestDiscoverTests(t *testing.T) { paths: []string{"../../testdata/discovery/manifests"}, want: []Test{{ BasePath: "../../testdata/discovery/manifests", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", diff --git a/pkg/discovery/load_test.go b/pkg/discovery/load_test.go index 5f4a72a24..96af292ce 100644 --- a/pkg/discovery/load_test.go +++ b/pkg/discovery/load_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" + "github.com/kyverno/chainsaw/pkg/model" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -36,7 +37,7 @@ func TestLoadTest(t *testing.T) { path: filepath.Join(basePath, "test"), want: []Test{{ BasePath: "../../testdata/discovery/test", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", @@ -84,7 +85,7 @@ func TestLoadTest(t *testing.T) { path: filepath.Join(basePath, "test"), want: []Test{{ BasePath: "../../testdata/discovery/test", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", @@ -132,7 +133,7 @@ func TestLoadTest(t *testing.T) { path: filepath.Join(basePath, "test-yml"), want: []Test{{ BasePath: "../../testdata/discovery/test-yml", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", @@ -180,7 +181,7 @@ func TestLoadTest(t *testing.T) { path: filepath.Join(basePath, "manifests"), want: []Test{{ BasePath: "../../testdata/discovery/manifests", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", @@ -235,7 +236,7 @@ func TestLoadTest(t *testing.T) { path: filepath.Join(basePath, "multiple-tests"), want: []Test{{ BasePath: "../../testdata/discovery/multiple-tests", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", @@ -277,7 +278,7 @@ func TestLoadTest(t *testing.T) { }, }, { BasePath: "../../testdata/discovery/multiple-tests", - Test: &v1alpha1.Test{ + Test: &model.Test{ TypeMeta: metav1.TypeMeta{ APIVersion: "chainsaw.kyverno.io/v1alpha1", Kind: "Test", diff --git a/pkg/discovery/test.go b/pkg/discovery/test.go index 51ef5c6f9..30b0c345c 100644 --- a/pkg/discovery/test.go +++ b/pkg/discovery/test.go @@ -1,11 +1,11 @@ package discovery import ( - "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" + "github.com/kyverno/chainsaw/pkg/model" ) type Test struct { - Test *v1alpha1.Test + Test *model.Test BasePath string Err error } diff --git a/pkg/model/model.go b/pkg/model/model.go new file mode 100644 index 000000000..402dbd9c2 --- /dev/null +++ b/pkg/model/model.go @@ -0,0 +1,11 @@ +package model + +import ( + "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" + "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" +) + +type ( + Configuration = v1alpha2.ConfigurationSpec + Test = v1alpha1.Test +) diff --git a/pkg/runner/flags/flags.go b/pkg/runner/flags/flags.go index c269de391..b011d73e4 100644 --- a/pkg/runner/flags/flags.go +++ b/pkg/runner/flags/flags.go @@ -3,10 +3,10 @@ package flags import ( "strconv" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" + "github.com/kyverno/chainsaw/pkg/model" ) -func GetFlags(config v1alpha2.ConfigurationSpec) map[string]string { +func GetFlags(config model.Configuration) map[string]string { flags := map[string]string{ "test.v": "true", "test.paniconexit0": "true", diff --git a/pkg/runner/flags/flags_test.go b/pkg/runner/flags/flags_test.go index 6cda5a78e..416e5c53e 100644 --- a/pkg/runner/flags/flags_test.go +++ b/pkg/runner/flags/flags_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" + "github.com/kyverno/chainsaw/pkg/model" "github.com/stretchr/testify/assert" "k8s.io/utils/ptr" ) @@ -11,11 +12,11 @@ import ( func TestGetFlags(t *testing.T) { tests := []struct { name string - config v1alpha2.ConfigurationSpec + config model.Configuration want map[string]string }{{ name: "default", - config: v1alpha2.ConfigurationSpec{}, + config: model.Configuration{}, want: map[string]string{ "test.v": "true", "test.paniconexit0": "true", @@ -25,7 +26,7 @@ func TestGetFlags(t *testing.T) { }, }, { name: "include", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Discovery: v1alpha2.DiscoveryOptions{ IncludeTestRegex: "^.*$", }, @@ -39,7 +40,7 @@ func TestGetFlags(t *testing.T) { }, }, { name: "exclude", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Discovery: v1alpha2.DiscoveryOptions{ ExcludeTestRegex: "^.*$", }, @@ -53,7 +54,7 @@ func TestGetFlags(t *testing.T) { }, }, { name: "parallel", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Execution: v1alpha2.ExecutionOptions{ Parallel: ptr.To(10), }, @@ -68,7 +69,7 @@ func TestGetFlags(t *testing.T) { }, }, { name: "repeat count", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Execution: v1alpha2.ExecutionOptions{ RepeatCount: ptr.To(10), }, diff --git a/pkg/runner/internal/flags.go b/pkg/runner/internal/flags.go index dd4470741..eed4cb86c 100644 --- a/pkg/runner/internal/flags.go +++ b/pkg/runner/internal/flags.go @@ -4,11 +4,11 @@ import ( "flag" "testing" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/runner/flags" ) -func SetupFlags(config v1alpha2.ConfigurationSpec) error { +func SetupFlags(config model.Configuration) error { testing.Init() for k, v := range flags.GetFlags(config) { if err := flag.Set(k, v); err != nil { diff --git a/pkg/runner/names/test.go b/pkg/runner/names/test.go index 0583496d8..53ddae61a 100644 --- a/pkg/runner/names/test.go +++ b/pkg/runner/names/test.go @@ -6,8 +6,8 @@ import ( "os" "path/filepath" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" ) type ( @@ -16,7 +16,7 @@ type ( relativePathInterface = func(string, string) (string, error) ) -func Test(config v1alpha2.ConfigurationSpec, test discovery.Test) (string, error) { +func Test(config model.Configuration, test discovery.Test) (string, error) { if test.Test == nil { return "", errors.New("test must not be nil") } diff --git a/pkg/runner/names/test_test.go b/pkg/runner/names/test_test.go index cebccf2d6..fa4058bef 100644 --- a/pkg/runner/names/test_test.go +++ b/pkg/runner/names/test_test.go @@ -6,9 +6,9 @@ import ( "path/filepath" "testing" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -18,13 +18,13 @@ func TestTest(t *testing.T) { assert.NoError(t, err) tests := []struct { name string - config v1alpha2.ConfigurationSpec + config model.Configuration test discovery.Test want string wantErr bool }{{ name: "nil test", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Discovery: v1alpha2.DiscoveryOptions{ FullName: false, }, @@ -36,14 +36,14 @@ func TestTest(t *testing.T) { wantErr: true, }, { name: "no full name", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Discovery: v1alpha2.DiscoveryOptions{ FullName: false, }, }, test: discovery.Test{ BasePath: cwd, - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", }, @@ -53,14 +53,14 @@ func TestTest(t *testing.T) { want: "foo", }, { name: "full name", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Discovery: v1alpha2.DiscoveryOptions{ FullName: true, }, }, test: discovery.Test{ BasePath: cwd, - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", }, @@ -70,14 +70,14 @@ func TestTest(t *testing.T) { want: ".[foo]", }, { name: "full name", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Discovery: v1alpha2.DiscoveryOptions{ FullName: true, }, }, test: discovery.Test{ BasePath: filepath.Join(cwd, "..", "dir", "dir"), - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", }, @@ -87,14 +87,14 @@ func TestTest(t *testing.T) { want: "../dir/dir[foo]", }, { name: "full name", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Discovery: v1alpha2.DiscoveryOptions{ FullName: true, }, }, test: discovery.Test{ BasePath: filepath.Join(cwd, "dir", "dir"), - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", }, @@ -147,7 +147,7 @@ func TestHelpTest(t *testing.T) { t.Run(tc.name, func(t *testing.T) { test := discovery.Test{ BasePath: "/some/path", - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", }, diff --git a/pkg/runner/processors/step.go b/pkg/runner/processors/step.go index 7c4d72a1d..1582a59eb 100644 --- a/pkg/runner/processors/step.go +++ b/pkg/runner/processors/step.go @@ -9,10 +9,10 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/binding" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/client" "github.com/kyverno/chainsaw/pkg/discovery" "github.com/kyverno/chainsaw/pkg/loaders/resource" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" apibindings "github.com/kyverno/chainsaw/pkg/runner/bindings" "github.com/kyverno/chainsaw/pkg/runner/cleanup" @@ -50,7 +50,7 @@ type StepProcessor interface { } func NewStepProcessor( - config v1alpha2.ConfigurationSpec, + config model.Configuration, clusters clusters.Registry, namespacer namespacer.Namespacer, clock clock.PassiveClock, @@ -71,7 +71,7 @@ func NewStepProcessor( } type stepProcessor struct { - config v1alpha2.ConfigurationSpec + config model.Configuration clusters clusters.Registry namespacer namespacer.Namespacer clock clock.PassiveClock diff --git a/pkg/runner/processors/step_test.go b/pkg/runner/processors/step_test.go index 33b193e3d..295cfa636 100644 --- a/pkg/runner/processors/step_test.go +++ b/pkg/runner/processors/step_test.go @@ -10,6 +10,7 @@ import ( "github.com/kyverno/chainsaw/pkg/client" fake "github.com/kyverno/chainsaw/pkg/client/testing" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" "github.com/kyverno/chainsaw/pkg/runner/logging" fakeLogger "github.com/kyverno/chainsaw/pkg/runner/logging/testing" @@ -29,7 +30,7 @@ func TestStepProcessor_Run(t *testing.T) { testData := filepath.Join("..", "..", "..", "testdata", "runner", "processors") testCases := []struct { name string - config v1alpha2.ConfigurationSpec + config model.Configuration client client.Client namespacer *fakeNamespacer.FakeNamespacer clock clock.PassiveClock @@ -40,7 +41,7 @@ func TestStepProcessor_Run(t *testing.T) { skipped bool }{{ name: "test with no handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{}, @@ -52,7 +53,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -69,7 +70,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: nil, }, { name: "try operation with apply handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -88,7 +89,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -116,7 +117,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "try operation with create handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -135,7 +136,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -163,7 +164,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "try operation with assert handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -206,7 +207,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -234,7 +235,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "try operation with error handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -277,7 +278,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -305,7 +306,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "try operation with command handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{}, @@ -320,7 +321,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -345,7 +346,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "try operation with script handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{}, @@ -360,7 +361,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -384,7 +385,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "try operation with sleep handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{}, @@ -392,7 +393,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -416,7 +417,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "try operation with delete handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -432,7 +433,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -465,7 +466,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "dry run with create handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -484,7 +485,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -515,7 +516,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: nil, }, { name: "skip delete with create handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -534,7 +535,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -563,7 +564,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: nil, }, { name: "try-raw resource with create handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -582,7 +583,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -617,7 +618,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: nil, }, { name: "try-url resource with create handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -636,7 +637,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -665,7 +666,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: nil, }, { name: "raw resource with assert handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -708,7 +709,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -759,7 +760,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: nil, }, { name: "try url-resource with assert handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha1.Timeouts{}, }, client: &fake.FakeClient{ @@ -788,7 +789,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -816,7 +817,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: nil, }, { name: "try, catch and finally operation with apply handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Execution: v1alpha2.ExecutionOptions{ ForceTerminationGracePeriod: &metav1.Duration{Duration: time.Duration(1) * time.Second}, }, @@ -866,7 +867,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, }, @@ -942,7 +943,7 @@ func TestStepProcessor_Run(t *testing.T) { stepReport: &report.StepReport{}, }, { name: "termination with create handler", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -961,7 +962,7 @@ func TestStepProcessor_Run(t *testing.T) { clock: tclock.NewFakePassiveClock(time.Now()), test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ ForceTerminationGracePeriod: &metav1.Duration{Duration: time.Duration(1) * time.Second}, Timeouts: &v1alpha1.Timeouts{}, diff --git a/pkg/runner/processors/test.go b/pkg/runner/processors/test.go index fb8330b84..29e7b2d8f 100644 --- a/pkg/runner/processors/test.go +++ b/pkg/runner/processors/test.go @@ -8,9 +8,9 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/binding" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/client" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" apibindings "github.com/kyverno/chainsaw/pkg/runner/bindings" "github.com/kyverno/chainsaw/pkg/runner/cleanup" @@ -37,7 +37,7 @@ type TestProcessor interface { } func NewTestProcessor( - config v1alpha2.ConfigurationSpec, + config model.Configuration, clusters clusters.Registry, clock clock.PassiveClock, summary *summary.Summary, @@ -58,7 +58,7 @@ func NewTestProcessor( } type testProcessor struct { - config v1alpha2.ConfigurationSpec + config model.Configuration clusters clusters.Registry clock clock.PassiveClock summary *summary.Summary diff --git a/pkg/runner/processors/test_test.go b/pkg/runner/processors/test_test.go index 36770edc9..8e0fa8b67 100644 --- a/pkg/runner/processors/test_test.go +++ b/pkg/runner/processors/test_test.go @@ -12,6 +12,7 @@ import ( "github.com/kyverno/chainsaw/pkg/client" fake "github.com/kyverno/chainsaw/pkg/client/testing" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" fakeNamespacer "github.com/kyverno/chainsaw/pkg/runner/namespacer/testing" "github.com/kyverno/chainsaw/pkg/runner/summary" @@ -28,7 +29,7 @@ import ( func TestTestProcessor_Run(t *testing.T) { testCases := []struct { name string - config v1alpha2.ConfigurationSpec + config model.Configuration client client.Client clock clock.PassiveClock summary *summary.Summary @@ -41,7 +42,7 @@ func TestTestProcessor_Run(t *testing.T) { skipped bool }{{ name: "test with no steps", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -54,7 +55,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Namespace: "chainsaw", Timeouts: &v1alpha1.Timeouts{}, @@ -67,7 +68,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "test with test steps", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -80,7 +81,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, Steps: []v1alpha1.TestStep{ @@ -97,7 +98,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "fail fast", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Execution: v1alpha2.ExecutionOptions{ FailFast: true, }, @@ -113,7 +114,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, Steps: []v1alpha1.TestStep{ @@ -130,7 +131,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "skip test", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -143,7 +144,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, Skip: ptr.To[bool](true), @@ -166,7 +167,7 @@ func TestTestProcessor_Run(t *testing.T) { skipped: true, }, { name: "with test namespace", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -179,7 +180,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Namespace: "chainsaw", Timeouts: &v1alpha1.Timeouts{}, @@ -201,7 +202,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "without test namespace", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -214,7 +215,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Timeouts: &v1alpha1.Timeouts{}, Steps: []v1alpha1.TestStep{ @@ -231,7 +232,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "delay before cleanup", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -244,7 +245,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ DelayBeforeCleanup: ptr.To[v1.Duration](v1.Duration{Duration: 1 * time.Second}), Timeouts: &v1alpha1.Timeouts{}, @@ -262,7 +263,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "namespace not found and created", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -278,7 +279,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Namespace: "chainsaw", Timeouts: &v1alpha1.Timeouts{}, @@ -300,7 +301,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "namespace not found due to internal error", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -316,7 +317,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Namespace: "chainsaw", Timeouts: &v1alpha1.Timeouts{}, @@ -338,7 +339,7 @@ func TestTestProcessor_Run(t *testing.T) { expectedFail: true, }, { name: "namespace not found and not created due to internal error", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Timeouts: v1alpha2.Timeouts{}, }, client: &fake.FakeClient{ @@ -354,7 +355,7 @@ func TestTestProcessor_Run(t *testing.T) { testsReport: nil, test: discovery.Test{ Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ Spec: v1alpha1.TestSpec{ Namespace: "chainsaw", Timeouts: &v1alpha1.Timeouts{}, diff --git a/pkg/runner/processors/tests.go b/pkg/runner/processors/tests.go index d2a21058d..a40a69ca5 100644 --- a/pkg/runner/processors/tests.go +++ b/pkg/runner/processors/tests.go @@ -7,9 +7,9 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/binding" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/client" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" apibindings "github.com/kyverno/chainsaw/pkg/runner/bindings" "github.com/kyverno/chainsaw/pkg/runner/cleanup" @@ -36,7 +36,7 @@ type TestsProcessor interface { } func NewTestsProcessor( - config v1alpha2.ConfigurationSpec, + config model.Configuration, clusters clusters.Registry, clock clock.PassiveClock, summary *summary.Summary, @@ -54,7 +54,7 @@ func NewTestsProcessor( } type testsProcessor struct { - config v1alpha2.ConfigurationSpec + config model.Configuration clusters clusters.Registry clock clock.PassiveClock summary *summary.Summary diff --git a/pkg/runner/processors/tests_test.go b/pkg/runner/processors/tests_test.go index 955e16eac..a4e3240b7 100644 --- a/pkg/runner/processors/tests_test.go +++ b/pkg/runner/processors/tests_test.go @@ -9,6 +9,7 @@ import ( "github.com/kyverno/chainsaw/pkg/client" fake "github.com/kyverno/chainsaw/pkg/client/testing" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" "github.com/kyverno/chainsaw/pkg/runner/clusters" "github.com/kyverno/chainsaw/pkg/runner/summary" @@ -35,7 +36,7 @@ func (r registryMock) Resolve(bool, ...string) (*rest.Config, client.Client, err func TestTestsProcessor_Run(t *testing.T) { testCases := []struct { name string - config v1alpha2.ConfigurationSpec + config model.Configuration client client.Client clock clock.PassiveClock summary *summary.Summary @@ -45,7 +46,7 @@ func TestTestsProcessor_Run(t *testing.T) { expectedFail bool }{{ name: "Namesapce exists", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Namespace: v1alpha2.NamespaceOptions{ Name: "default", }, @@ -63,7 +64,7 @@ func TestTestsProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "Namesapce doesn't exists", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Namespace: v1alpha2.NamespaceOptions{ Name: "chain-saw", }, @@ -87,7 +88,7 @@ func TestTestsProcessor_Run(t *testing.T) { expectedFail: false, }, { name: "Namesapce not found with error", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Namespace: v1alpha2.NamespaceOptions{ Name: "chain-saw", }, @@ -108,7 +109,7 @@ func TestTestsProcessor_Run(t *testing.T) { expectedFail: true, }, { name: "Namesapce doesn't exists and can't be created", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Namespace: v1alpha2.NamespaceOptions{ Name: "chain-saw", }, @@ -129,7 +130,7 @@ func TestTestsProcessor_Run(t *testing.T) { expectedFail: true, }, { name: "Success", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Namespace: v1alpha2.NamespaceOptions{ Name: "default", }, @@ -147,13 +148,13 @@ func TestTestsProcessor_Run(t *testing.T) { { Err: nil, BasePath: "fakePath", - Test: &v1alpha1.Test{}, + Test: &model.Test{}, }, }, expectedFail: false, }, { name: "Fail", - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Namespace: v1alpha2.NamespaceOptions{ Name: "default", }, diff --git a/pkg/runner/run.go b/pkg/runner/run.go index 27aaeb3de..04b0610ed 100644 --- a/pkg/runner/run.go +++ b/pkg/runner/run.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/jmespath-community/go-jmespath/pkg/binding" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" apibindings "github.com/kyverno/chainsaw/pkg/runner/bindings" "github.com/kyverno/chainsaw/pkg/runner/clusters" @@ -27,7 +27,7 @@ func Run( ctx context.Context, cfg *rest.Config, clock clock.PassiveClock, - config v1alpha2.ConfigurationSpec, + config model.Configuration, values map[string]any, tests ...discovery.Test, ) (*summary.Summary, error) { @@ -38,7 +38,7 @@ func run( ctx context.Context, cfg *rest.Config, clock clock.PassiveClock, - config v1alpha2.ConfigurationSpec, + config model.Configuration, m mainstart, values map[string]any, tests ...discovery.Test, diff --git a/pkg/runner/run_test.go b/pkg/runner/run_test.go index 4052e183e..4e50192d9 100644 --- a/pkg/runner/run_test.go +++ b/pkg/runner/run_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/model" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/rest" @@ -28,14 +28,14 @@ func TestRun(t *testing.T) { tests := []struct { name string tests []discovery.Test - config v1alpha2.ConfigurationSpec + config model.Configuration restConfig *rest.Config mockReturn int wantErr bool }{{ name: "Zero Tests", tests: []discovery.Test{}, - config: v1alpha2.ConfigurationSpec{}, + config: model.Configuration{}, restConfig: &rest.Config{}, wantErr: false, }, { @@ -43,14 +43,14 @@ func TestRun(t *testing.T) { tests: []discovery.Test{ { Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "test1", }, }, }, }, - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Report: &v1alpha2.ReportOptions{ Format: v1alpha2.JSONFormat, }, @@ -60,7 +60,7 @@ func TestRun(t *testing.T) { }, { name: "Zero Tests with JSON Report", tests: []discovery.Test{}, - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Report: &v1alpha2.ReportOptions{ Format: v1alpha2.JSONFormat, }, @@ -72,7 +72,7 @@ func TestRun(t *testing.T) { tests: []discovery.Test{ { Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "test1", }, @@ -87,7 +87,7 @@ func TestRun(t *testing.T) { tests: []discovery.Test{ { Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "test1", }, @@ -102,14 +102,14 @@ func TestRun(t *testing.T) { tests: []discovery.Test{ { Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "test1", }, }, }, }, - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Report: &v1alpha2.ReportOptions{ Format: v1alpha2.XMLFormat, Name: "chainsaw", @@ -123,14 +123,14 @@ func TestRun(t *testing.T) { tests: []discovery.Test{ { Err: nil, - Test: &v1alpha1.Test{ + Test: &model.Test{ ObjectMeta: metav1.ObjectMeta{ Name: "test1", }, }, }, }, - config: v1alpha2.ConfigurationSpec{ + config: model.Configuration{ Report: &v1alpha2.ReportOptions{ Format: "abc", },