github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/pkg/clients/integration/integration_test_scenarios.go (about) 1 package integration 2 3 import ( 4 "context" 5 6 "github.com/devfile/library/v2/pkg/util" 7 "github.com/redhat-appstudio/e2e-tests/pkg/constants" 8 integrationv1beta1 "github.com/konflux-ci/integration-service/api/v1beta1" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 "sigs.k8s.io/controller-runtime/pkg/client" 11 ) 12 13 // CreateIntegrationTestScenario creates beta1 version integrationTestScenario. 14 func (i *IntegrationController) CreateIntegrationTestScenario(itsName, applicationName, namespace, gitURL, revision, pathInRepo string) (*integrationv1beta1.IntegrationTestScenario, error) { 15 if itsName == "" { 16 itsName = "my-integration-test-" + util.GenerateRandomString(4) 17 } 18 19 integrationTestScenario := &integrationv1beta1.IntegrationTestScenario{ 20 ObjectMeta: metav1.ObjectMeta{ 21 Name: itsName, 22 Namespace: namespace, 23 Labels: constants.IntegrationTestScenarioDefaultLabels, 24 }, 25 Spec: integrationv1beta1.IntegrationTestScenarioSpec{ 26 Application: applicationName, 27 ResolverRef: integrationv1beta1.ResolverRef{ 28 Resolver: "git", 29 Params: []integrationv1beta1.ResolverParameter{ 30 { 31 Name: "url", 32 Value: gitURL, 33 }, 34 { 35 Name: "revision", 36 Value: revision, 37 }, 38 { 39 Name: "pathInRepo", 40 Value: pathInRepo, 41 }, 42 }, 43 }, 44 }, 45 } 46 47 err := i.KubeRest().Create(context.Background(), integrationTestScenario) 48 if err != nil { 49 return nil, err 50 } 51 return integrationTestScenario, nil 52 } 53 54 // Get return the status from the Application Custom Resource object. 55 func (i *IntegrationController) GetIntegrationTestScenarios(applicationName, namespace string) (*[]integrationv1beta1.IntegrationTestScenario, error) { 56 opts := []client.ListOption{ 57 client.InNamespace(namespace), 58 } 59 60 integrationTestScenarioList := &integrationv1beta1.IntegrationTestScenarioList{} 61 err := i.KubeRest().List(context.Background(), integrationTestScenarioList, opts...) 62 if err != nil { 63 return nil, err 64 } 65 66 items := make([]integrationv1beta1.IntegrationTestScenario, 0) 67 for _, t := range integrationTestScenarioList.Items { 68 if t.Spec.Application == applicationName { 69 items = append(items, t) 70 } 71 } 72 return &items, nil 73 } 74 75 // DeleteIntegrationTestScenario removes given testScenario from specified namespace. 76 func (i *IntegrationController) DeleteIntegrationTestScenario(testScenario *integrationv1beta1.IntegrationTestScenario, namespace string) error { 77 err := i.KubeRest().Delete(context.Background(), testScenario) 78 return err 79 }