github.com/kubeshop/testkube@v1.17.23/pkg/mapper/testsuites/kube_openapi_test.go (about)

     1  package testsuites
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     9  
    10  	testsuitesv3 "github.com/kubeshop/testkube-operator/api/testsuite/v3"
    11  )
    12  
    13  func TestMapTestSuiteListKubeToAPI(t *testing.T) {
    14  
    15  	openAPITest := MapCRToAPI(
    16  		testsuitesv3.TestSuite{
    17  			Spec: testsuitesv3.TestSuiteSpec{
    18  				Before: []testsuitesv3.TestSuiteBatchStep{
    19  					{
    20  						Execute: []testsuitesv3.TestSuiteStepSpec{
    21  							{
    22  								Delay: metav1.Duration{Duration: 2 * time.Second},
    23  							},
    24  						},
    25  					},
    26  				},
    27  
    28  				Steps: []testsuitesv3.TestSuiteBatchStep{
    29  					{
    30  						Execute: []testsuitesv3.TestSuiteStepSpec{
    31  							{
    32  								Test: "some-test-name",
    33  							},
    34  						},
    35  					},
    36  				},
    37  
    38  				After: []testsuitesv3.TestSuiteBatchStep{
    39  					{
    40  						Execute: []testsuitesv3.TestSuiteStepSpec{
    41  							{
    42  								Delay: metav1.Duration{Duration: time.Second},
    43  							},
    44  						},
    45  					},
    46  				},
    47  
    48  				Repeats: 2,
    49  			},
    50  		},
    51  	)
    52  
    53  	assert.Equal(t, 1, len(openAPITest.Before))
    54  	assert.Equal(t, "2s", openAPITest.Before[0].Execute[0].Delay)
    55  	assert.Equal(t, 1, len(openAPITest.Steps))
    56  	assert.Equal(t, "some-test-name", openAPITest.Steps[0].Execute[0].Test)
    57  	assert.Equal(t, 1, len(openAPITest.After))
    58  	assert.Equal(t, "1s", openAPITest.After[0].Execute[0].Delay)
    59  }
    60  
    61  func TestMapTestSuiteTestCRDToUpdateRequest(t *testing.T) {
    62  
    63  	openAPITest := MapTestSuiteTestCRDToUpdateRequest(
    64  		&testsuitesv3.TestSuite{
    65  			Spec: testsuitesv3.TestSuiteSpec{
    66  				Before: []testsuitesv3.TestSuiteBatchStep{
    67  					{
    68  						Execute: []testsuitesv3.TestSuiteStepSpec{
    69  							{
    70  								Delay: metav1.Duration{Duration: 2 * time.Second},
    71  							},
    72  						},
    73  					},
    74  				},
    75  
    76  				Steps: []testsuitesv3.TestSuiteBatchStep{
    77  					{
    78  						Execute: []testsuitesv3.TestSuiteStepSpec{
    79  							{
    80  								Test: "some-test-name",
    81  							},
    82  						},
    83  					},
    84  				},
    85  
    86  				After: []testsuitesv3.TestSuiteBatchStep{
    87  					{
    88  						Execute: []testsuitesv3.TestSuiteStepSpec{
    89  							{
    90  								Delay: metav1.Duration{Duration: time.Second},
    91  							},
    92  						},
    93  					},
    94  				},
    95  
    96  				Repeats: 2,
    97  			},
    98  		},
    99  	)
   100  
   101  	assert.Equal(t, 1, len(*openAPITest.Before))
   102  	assert.Equal(t, "2s", (*openAPITest.Before)[0].Execute[0].Delay)
   103  	assert.Equal(t, 1, len(*openAPITest.Steps))
   104  	assert.Equal(t, "some-test-name", (*openAPITest.Steps)[0].Execute[0].Test)
   105  	assert.Equal(t, 1, len(*openAPITest.After))
   106  	assert.Equal(t, "1s", (*openAPITest.After)[0].Execute[0].Delay)
   107  }