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

     1  package tests
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	v1 "k8s.io/api/core/v1"
     9  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    10  
    11  	testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3"
    12  	"github.com/kubeshop/testkube/pkg/api/v1/testkube"
    13  )
    14  
    15  func TestMapTestCRToAPI(t *testing.T) {
    16  	test := testsv3.Test{
    17  		TypeMeta: metav1.TypeMeta{
    18  			Kind:       "Test",
    19  			APIVersion: "tests.testkube.io/v3",
    20  		},
    21  		ObjectMeta: metav1.ObjectMeta{
    22  			Name:              "test-1",
    23  			Namespace:         "testkube",
    24  			CreationTimestamp: metav1.NewTime(time.Time{}),
    25  		},
    26  		Spec: testsv3.TestSpec{
    27  			Type_: "curl/test",
    28  			Name:  "test-1",
    29  			Content: &testsv3.TestContent{
    30  				Type_: "string",
    31  				Data:  "123",
    32  			},
    33  			ExecutionRequest: &testsv3.ExecutionRequest{
    34  				Name:   "",
    35  				Number: 1,
    36  				ExecutionLabels: map[string]string{
    37  					"": "",
    38  				},
    39  				Args:    []string{"-v", "-X", "GET", "https://testkube.kubeshop.io"},
    40  				Command: []string{"curl"},
    41  				Image:   "curlimages/curl:7.85.0",
    42  				ImagePullSecrets: []v1.LocalObjectReference{
    43  					{Name: "secret"},
    44  				},
    45  				Envs: map[string]string{
    46  					"TESTKUBE": "1",
    47  				},
    48  				Sync: false,
    49  				EnvConfigMaps: []testsv3.EnvReference{
    50  					{
    51  						LocalObjectReference: v1.LocalObjectReference{
    52  							Name: "configmap",
    53  						},
    54  						Mount:          true,
    55  						MountPath:      "/data",
    56  						MapToVariables: false,
    57  					},
    58  				},
    59  				EnvSecrets: []testsv3.EnvReference{
    60  					{
    61  						LocalObjectReference: v1.LocalObjectReference{
    62  							Name: "secret",
    63  						},
    64  						Mount:          false,
    65  						MountPath:      "",
    66  						MapToVariables: true,
    67  					},
    68  				},
    69  			},
    70  		},
    71  	}
    72  	got := MapTestCRToAPI(test)
    73  
    74  	want := testkube.Test{
    75  		Name:      "test-1",
    76  		Namespace: "testkube",
    77  		Type_:     "curl/test",
    78  		Content: &testkube.TestContent{
    79  			Type_: "string",
    80  			Data:  "123",
    81  		},
    82  		Created: time.Time{},
    83  		ExecutionRequest: &testkube.ExecutionRequest{
    84  			Name:   "",
    85  			Number: 1,
    86  			ExecutionLabels: map[string]string{
    87  				"": "",
    88  			},
    89  			Namespace:     "",
    90  			Variables:     map[string]testkube.Variable{},
    91  			VariablesFile: "",
    92  			Args:          []string{"-v", "-X", "GET", "https://testkube.kubeshop.io"},
    93  			ArgsMode:      "",
    94  			Command:       []string{"curl"},
    95  			Image:         "curlimages/curl:7.85.0",
    96  			ImagePullSecrets: []testkube.LocalObjectReference{
    97  				{Name: "secret"},
    98  			},
    99  			Envs: map[string]string{
   100  				"TESTKUBE": "1",
   101  			},
   102  			Sync: false,
   103  			EnvConfigMaps: []testkube.EnvReference{
   104  				{
   105  					Reference: &testkube.LocalObjectReference{
   106  						Name: "configmap",
   107  					},
   108  					Mount:          true,
   109  					MountPath:      "/data",
   110  					MapToVariables: false,
   111  				},
   112  			},
   113  			EnvSecrets: []testkube.EnvReference{
   114  				{
   115  					Reference: &testkube.LocalObjectReference{
   116  						Name: "secret",
   117  					},
   118  					Mount:          false,
   119  					MountPath:      "",
   120  					MapToVariables: true,
   121  				},
   122  			},
   123  		},
   124  	}
   125  	assert.Equal(t, want, got)
   126  }