github.com/xgoffin/jenkins-library@v1.154.0/cmd/integrationArtifactUpdateConfiguration_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/SAP/jenkins-library/pkg/mock"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  type integrationArtifactUpdateConfigurationMockUtils struct {
    11  	*mock.ExecMockRunner
    12  }
    13  
    14  func newIntegrationArtifactUpdateConfigurationTestsUtils() integrationArtifactUpdateConfigurationMockUtils {
    15  	utils := integrationArtifactUpdateConfigurationMockUtils{
    16  		ExecMockRunner: &mock.ExecMockRunner{},
    17  	}
    18  	return utils
    19  }
    20  
    21  func TestRunIntegrationArtifactUpdateConfiguration(t *testing.T) {
    22  	t.Parallel()
    23  
    24  	t.Run("Successfully update of Integration Flow configuration parameter test", func(t *testing.T) {
    25  		apiServiceKey := `{
    26  			"oauth": {
    27  				"url": "https://demo",
    28  				"clientid": "demouser",
    29  				"clientsecret": "******",
    30  				"tokenurl": "https://demo/oauth/token"
    31  			}
    32  		}`
    33  		config := integrationArtifactUpdateConfigurationOptions{
    34  			APIServiceKey:          apiServiceKey,
    35  			IntegrationFlowID:      "flow1",
    36  			IntegrationFlowVersion: "1.0.1",
    37  			ParameterKey:           "myheader",
    38  			ParameterValue:         "def",
    39  		}
    40  
    41  		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Positive", Method: "PUT", URL: "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')"}
    42  
    43  		err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient)
    44  
    45  		if assert.NoError(t, err) {
    46  
    47  			t.Run("check url", func(t *testing.T) {
    48  				assert.Equal(t, "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')", httpClient.URL)
    49  			})
    50  
    51  			t.Run("check method", func(t *testing.T) {
    52  				assert.Equal(t, "PUT", httpClient.Method)
    53  			})
    54  		}
    55  
    56  	})
    57  
    58  	t.Run("Failed case of Integration Flow configuration parameter Test", func(t *testing.T) {
    59  		apiServiceKey := `{
    60  			"oauth": {
    61  				"url": "https://demo",
    62  				"clientid": "demouser",
    63  				"clientsecret": "******",
    64  				"tokenurl": "https://demo/oauth/token"
    65  			}
    66  		}`
    67  		config := integrationArtifactUpdateConfigurationOptions{
    68  			APIServiceKey:          apiServiceKey,
    69  			IntegrationFlowID:      "flow1",
    70  			IntegrationFlowVersion: "1.0.1",
    71  			ParameterKey:           "myheader",
    72  			ParameterValue:         "def",
    73  		}
    74  
    75  		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative"}
    76  
    77  		err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient)
    78  		assert.EqualError(t, err, "HTTP \"PUT\" request to \"https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')\" failed with error: Not found - either wrong version for the given Id or wrong parameter key")
    79  	})
    80  
    81  	t.Run("Failed case of Integration Flow configuration parameter test with error body", func(t *testing.T) {
    82  		apiServiceKey := `{
    83  			"oauth": {
    84  				"url": "https://demo",
    85  				"clientid": "demouser",
    86  				"clientsecret": "******",
    87  				"tokenurl": "https://demo/oauth/token"
    88  			}
    89  		}`
    90  		config := integrationArtifactUpdateConfigurationOptions{
    91  			APIServiceKey:          apiServiceKey,
    92  			IntegrationFlowID:      "flow1",
    93  			IntegrationFlowVersion: "1.0.1",
    94  			ParameterKey:           "myheader",
    95  			ParameterValue:         "def",
    96  		}
    97  
    98  		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative_With_ResponseBody"}
    99  
   100  		err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient)
   101  		assert.EqualError(t, err, "Failed to update the integration flow configuration parameter, Response Status code: 400")
   102  	})
   103  }