2021-02-05 11:35:55 +02:00
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 ) {
2021-06-28 10:50:33 +02:00
apiServiceKey := ` {
"oauth" : {
"url" : "https://demo" ,
"clientid" : "demouser" ,
"clientsecret" : "******" ,
"tokenurl" : "https://demo/oauth/token"
}
} `
2021-02-05 11:35:55 +02:00
config := integrationArtifactGetServiceEndpointOptions {
2021-06-28 10:50:33 +02:00
APIServiceKey : apiServiceKey ,
IntegrationFlowID : "CPI_IFlow_Call_using_Cert" ,
2021-02-05 11:35:55 +02:00
}
httpClient := httpMockCpis { CPIFunction : "IntegrationArtifactGetServiceEndpoint" , ResponseBody : ` ` , TestType : "PositiveAndGetetIntegrationArtifactGetServiceResBody" }
seOut := integrationArtifactGetServiceEndpointCommonPipelineEnvironment { }
err := runIntegrationArtifactGetServiceEndpoint ( & config , nil , & httpClient , & seOut )
2021-08-04 16:42:25 +02:00
assert . EqualValues ( t , seOut . custom . integrationFlowServiceEndpoint , "https://demo.cfapps.sap.hana.ondemand.com/http/testwithcert" )
2021-02-05 11:35:55 +02:00
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 ) {
2021-06-28 10:50:33 +02:00
apiServiceKey := ` {
"oauth" : {
"url" : "https://demo" ,
"clientid" : "demouser" ,
"clientsecret" : "******" ,
"tokenurl" : "https://demo/oauth/token"
}
} `
2021-02-05 11:35:55 +02:00
config := integrationArtifactGetServiceEndpointOptions {
2021-06-28 10:50:33 +02:00
APIServiceKey : apiServiceKey ,
IntegrationFlowID : "CPI_IFlow_Call_using_Cert" ,
2021-02-05 11:35:55 +02:00
}
httpClient := httpMockCpis { CPIFunction : "IntegrationArtifactGetServiceEndpoint" , ResponseBody : ` ` , TestType : "Negative" }
seOut := integrationArtifactGetServiceEndpointCommonPipelineEnvironment { }
err := runIntegrationArtifactGetServiceEndpoint ( & config , nil , & httpClient , & seOut )
2021-08-04 16:42:25 +02:00
assert . EqualValues ( t , seOut . custom . integrationFlowServiceEndpoint , "" )
2021-02-05 11:35:55 +02:00
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" )
} )
}