github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/cmd/integrationArtifactUnDeploy_test.go (about)

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