1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/cloudFoundryCreateServiceKey_test.go

86 lines
3.3 KiB
Go
Raw Normal View History

package cmd
import (
"testing"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/stretchr/testify/assert"
)
func TestCloudFoundryCreateServiceKey(t *testing.T) {
execRunner := mock.ExecMockRunner{}
var telemetryData telemetry.CustomData
t.Run("CF Login: success case", func(t *testing.T) {
loginconfig := cloudFoundryDeleteServiceOptions{
CfAPIEndpoint: "https://api.endpoint.com",
CfOrg: "testOrg",
CfSpace: "testSpace",
Username: "testUser",
Password: "testPassword",
}
error := cloudFoundryLogin(loginconfig, &execRunner)
if error == nil {
assert.Equal(t, "cf", execRunner.Calls[0].Exec)
assert.Equal(t, []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}, execRunner.Calls[0].Params)
}
})
t.Run("CF Create Service Key: Success case", func(t *testing.T) {
config := cloudFoundryCreateServiceKeyOptions{
CfAPIEndpoint: "https://api.endpoint.com",
CfOrg: "testOrg",
CfSpace: "testSpace",
Username: "testUser",
Password: "testPassword",
CfServiceInstance: "testInstance",
CfServiceKeyName: "testKey",
}
error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner)
if error == nil {
assert.Equal(t, "cf", execRunner.Calls[1].Exec)
assert.Equal(t, []string{"create-service-key", "testInstance", "testKey"}, execRunner.Calls[1].Params)
}
})
t.Run("CF Create Service Key with service Key config: Success case", func(t *testing.T) {
config := cloudFoundryCreateServiceKeyOptions{
CfAPIEndpoint: "https://api.endpoint.com",
CfOrg: "testOrg",
CfSpace: "testSpace",
Username: "testUser",
Password: "testPassword",
CfServiceInstance: "testInstance",
CfServiceKeyName: "testKey",
CfServiceKeyConfig: "testconfig.yml",
}
error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner)
if error == nil {
assert.Equal(t, "cf", execRunner.Calls[2].Exec)
assert.Equal(t, []string{"create-service-key", "testInstance", "testKey", "-c", "testconfig.yml"}, execRunner.Calls[2].Params)
}
})
t.Run("CF Create Service Key with service Key config: Success case", func(t *testing.T) {
config := cloudFoundryCreateServiceKeyOptions{
CfAPIEndpoint: "https://api.endpoint.com",
CfOrg: "testOrg",
CfSpace: "testSpace",
Username: "testUser",
Password: "testPassword",
CfServiceInstance: "testInstance",
CfServiceKeyName: "testKey",
CfServiceKeyConfig: "{\"scenario_id\":\"SAP_COM_0510\",\"type\":\"basic\"}",
}
error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner)
if error == nil {
assert.Equal(t, "cf", execRunner.Calls[3].Exec)
assert.Equal(t, []string{"create-service-key", "testInstance", "testKey", "-c", "{\"scenario_id\":\"SAP_COM_0510\",\"type\":\"basic\"}"}, execRunner.Calls[3].Params)
}
})
t.Run("CF Logout: Success case", func(t *testing.T) {
error := cloudFoundryLogout(&execRunner)
if error == nil {
assert.Equal(t, "cf", execRunner.Calls[4].Exec)
assert.Equal(t, "logout", execRunner.Calls[4].Params[0])
}
})
}