github.com/jaylevin/jenkins-library@v1.230.4/cmd/integrationArtifactUnDeploy_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/SAP/jenkins-library/pkg/mock"
     5  	"github.com/stretchr/testify/assert"
     6  	"testing"
     7  )
     8  
     9  type integrationArtifactUnDeployMockUtils struct {
    10  	*mock.ExecMockRunner
    11  	*mock.FilesMock
    12  }
    13  
    14  func TestRunIntegrationArtifactUnDeploy(t *testing.T) {
    15  	t.Parallel()
    16  
    17  	t.Run("Successful undeploy of integration flow test", func(t *testing.T) {
    18  
    19  		apiServiceKey := `{
    20  			"oauth": {
    21  				"url": "https://demo",
    22  				"clientid": "demouser",
    23  				"clientsecret": "******",
    24  				"tokenurl": "https://demo/oauth/token"
    25  			}
    26  		}`
    27  		config := integrationArtifactUnDeployOptions{
    28  			APIServiceKey:     apiServiceKey,
    29  			IntegrationFlowID: "flow1",
    30  		}
    31  		httpClient := httpMockCpis{CPIFunction: "PositiveAndUnDeployIntegrationDesigntimeArtifact", ResponseBody: ``, TestType: "Positive"}
    32  
    33  		// test
    34  		err := runIntegrationArtifactUnDeploy(&config, nil, &httpClient)
    35  
    36  		// assert
    37  		assert.NoError(t, err)
    38  	})
    39  
    40  	t.Run("Failed undeploy of integration flow test", func(t *testing.T) {
    41  		apiServiceKey := `{
    42  			"oauth": {
    43  				"url": "https://demo",
    44  				"clientid": "demouser",
    45  				"clientsecret": "******",
    46  				"tokenurl": "https://demo/oauth/token"
    47  			}
    48  		}`
    49  		config := integrationArtifactUnDeployOptions{
    50  			APIServiceKey:     apiServiceKey,
    51  			IntegrationFlowID: "flow1",
    52  		}
    53  
    54  		httpClient := httpMockCpis{CPIFunction: "FailedIntegrationRuntimeArtifactUnDeployment", ResponseBody: ``, TestType: "Negative"}
    55  
    56  		// test
    57  		err := runIntegrationArtifactUnDeploy(&config, nil, &httpClient)
    58  
    59  		// assert
    60  		assert.EqualError(t, err, "integration flow undeployment failed, response Status code: 400")
    61  	})
    62  }