1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/integrationArtifactGetServiceEndpoint_test.go
Mayur Belur Mohan 538256774a
IntegrationArtifactGetServiceEndpoint Command (#2582)
* GetIntegrationArtifactServiceEndpoint Command

Co-authored-by: Marcus Holl <marcus.holl@sap.com>
2021-02-05 10:35:55 +01:00

73 lines
2.6 KiB
Go

package cmd
import (
"testing"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/stretchr/testify/assert"
)
type integrationArtifactGetServiceEndpointMockUtils struct {
*mock.ExecMockRunner
*mock.FilesMock
}
func newIntegrationArtifactGetServiceEndpointTestsUtils() integrationArtifactGetServiceEndpointMockUtils {
utils := integrationArtifactGetServiceEndpointMockUtils{
ExecMockRunner: &mock.ExecMockRunner{},
FilesMock: &mock.FilesMock{},
}
return utils
}
func TestRunIntegrationArtifactGetServiceEndpoint(t *testing.T) {
t.Parallel()
t.Run("Successfully Test of Get Integration Flow Service Endpoint", func(t *testing.T) {
config := integrationArtifactGetServiceEndpointOptions{
Host: "https://demo",
OAuthTokenProviderURL: "https://demo/oauth/token",
Username: "demouser",
Password: "******",
IntegrationFlowID: "CPI_IFlow_Call_using_Cert",
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetServiceEndpoint", ResponseBody: ``, TestType: "PositiveAndGetetIntegrationArtifactGetServiceResBody"}
seOut := integrationArtifactGetServiceEndpointCommonPipelineEnvironment{}
err := runIntegrationArtifactGetServiceEndpoint(&config, nil, &httpClient, &seOut)
assert.EqualValues(t, seOut.custom.iFlowServiceEndpoint, "https://demo.cfapps.sap.hana.ondemand.com/http/testwithcert")
if assert.NoError(t, err) {
t.Run("check url", func(t *testing.T) {
assert.Equal(t, "https://demo/api/v1/ServiceEndpoints?$expand=EntryPoints", httpClient.URL)
})
t.Run("check method", func(t *testing.T) {
assert.Equal(t, "GET", httpClient.Method)
})
}
})
t.Run("Failed Test of Get Integration Flow MPL Status", func(t *testing.T) {
config := integrationArtifactGetServiceEndpointOptions{
Host: "https://demo",
OAuthTokenProviderURL: "https://demo/oauth/token",
Username: "demouser",
Password: "******",
IntegrationFlowID: "CPI_IFlow_Call_using_Cert",
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetServiceEndpoint", ResponseBody: ``, TestType: "Negative"}
seOut := integrationArtifactGetServiceEndpointCommonPipelineEnvironment{}
err := runIntegrationArtifactGetServiceEndpoint(&config, nil, &httpClient, &seOut)
assert.EqualValues(t, seOut.custom.iFlowServiceEndpoint, "")
assert.EqualError(t, err, "HTTP GET request to https://demo/api/v1/ServiceEndpoints?$expand=EntryPoints failed with error: Unable to get integration flow service endpoint, Response Status code:400")
})
}