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
Linda Siebert b68f549923
CPI- Remove platform parameter (#2956)
* Remove platform from yaml and generated

* Remove from tests and md
2021-06-30 14:32:30 +02:00

81 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) {
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactGetServiceEndpointOptions{
APIServiceKey: apiServiceKey,
IntegrationFlowID: "CPI_IFlow_Call_using_Cert",
}
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) {
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactGetServiceEndpointOptions{
APIServiceKey: apiServiceKey,
IntegrationFlowID: "CPI_IFlow_Call_using_Cert",
}
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")
})
}