From 385c8886b90aeba181cbff9c8f54a1f96c5148c1 Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Wed, 5 Jul 2023 11:16:09 +0200 Subject: [PATCH] fix: map test suite YAML to proper update structure (#4129) --- pkg/mapper/testsuites/kube_openapi.go | 4 +- pkg/mapper/testsuites/kube_openapi_test.go | 55 +++++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/pkg/mapper/testsuites/kube_openapi.go b/pkg/mapper/testsuites/kube_openapi.go index ec3a42df7d2..1d2244bed67 100644 --- a/pkg/mapper/testsuites/kube_openapi.go +++ b/pkg/mapper/testsuites/kube_openapi.go @@ -225,10 +225,10 @@ func MapTestSuiteTestCRDToUpdateRequest(testSuite *testsuitesv3.TestSuite) (requ request.Before = &before steps := mapCRDToTestBatchSteps(testSuite.Spec.Steps) - request.Before = &steps + request.Steps = &steps after := mapCRDToTestBatchSteps(testSuite.Spec.After) - request.Before = &after + request.After = &after request.Labels = &testSuite.Labels diff --git a/pkg/mapper/testsuites/kube_openapi_test.go b/pkg/mapper/testsuites/kube_openapi_test.go index 5d8cf6f90d4..79704f9b13f 100644 --- a/pkg/mapper/testsuites/kube_openapi_test.go +++ b/pkg/mapper/testsuites/kube_openapi_test.go @@ -19,7 +19,7 @@ func TestMapTestSuiteListKubeToAPI(t *testing.T) { { Execute: []testsuitesv3.TestSuiteStepSpec{ { - Delay: metav1.Duration{Duration: time.Second}, + Delay: metav1.Duration{Duration: 2 * time.Second}, }, }, }, @@ -50,7 +50,58 @@ func TestMapTestSuiteListKubeToAPI(t *testing.T) { }, ) - assert.Equal(t, 1, len(openAPITest.Steps)) assert.Equal(t, 1, len(openAPITest.Before)) + assert.Equal(t, "2s", openAPITest.Before[0].Execute[0].Delay) + assert.Equal(t, 1, len(openAPITest.Steps)) + assert.Equal(t, "some-test-name", openAPITest.Steps[0].Execute[0].Test) assert.Equal(t, 1, len(openAPITest.After)) + assert.Equal(t, "1s", openAPITest.After[0].Execute[0].Delay) +} + +func TestMapTestSuiteTestCRDToUpdateRequest(t *testing.T) { + + openAPITest := MapTestSuiteTestCRDToUpdateRequest( + &testsuitesv3.TestSuite{ + Spec: testsuitesv3.TestSuiteSpec{ + Before: []testsuitesv3.TestSuiteBatchStep{ + { + Execute: []testsuitesv3.TestSuiteStepSpec{ + { + Delay: metav1.Duration{Duration: 2 * time.Second}, + }, + }, + }, + }, + + Steps: []testsuitesv3.TestSuiteBatchStep{ + { + Execute: []testsuitesv3.TestSuiteStepSpec{ + { + Test: "some-test-name", + }, + }, + }, + }, + + After: []testsuitesv3.TestSuiteBatchStep{ + { + Execute: []testsuitesv3.TestSuiteStepSpec{ + { + Delay: metav1.Duration{Duration: time.Second}, + }, + }, + }, + }, + + Repeats: 2, + }, + }, + ) + + assert.Equal(t, 1, len(*openAPITest.Before)) + assert.Equal(t, "2s", (*openAPITest.Before)[0].Execute[0].Delay) + assert.Equal(t, 1, len(*openAPITest.Steps)) + assert.Equal(t, "some-test-name", (*openAPITest.Steps)[0].Execute[0].Test) + assert.Equal(t, 1, len(*openAPITest.After)) + assert.Equal(t, "1s", (*openAPITest.After)[0].Execute[0].Delay) }