mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
ffc931aad1
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files. * Added unit build tag to all unit test files. * added to new unit test unit build tag * Update verify-go.yml * small fix --------- Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
70 lines
2.3 KiB
Go
70 lines
2.3 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
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.integrationFlowServiceEndpoint, "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.integrationFlowServiceEndpoint, "")
|
|
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")
|
|
})
|
|
|
|
}
|