2020-02-10 15:53:12 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-08-10 11:08:34 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/SAP/jenkins-library/pkg/cloudfoundry"
|
2020-02-27 13:11:22 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
2020-02-10 15:53:12 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCloudFoundryDeleteService(t *testing.T) {
|
|
|
|
|
2020-08-10 11:08:34 +02:00
|
|
|
t.Run("CF Delete Service : success case", func(t *testing.T) {
|
2020-02-10 15:53:12 +02:00
|
|
|
config := cloudFoundryDeleteServiceOptions{
|
2020-08-10 11:08:34 +02:00
|
|
|
CfAPIEndpoint: "https://api.endpoint.com",
|
|
|
|
CfOrg: "testOrg",
|
|
|
|
CfSpace: "testSpace",
|
|
|
|
Username: "testUser",
|
|
|
|
Password: "testPassword",
|
|
|
|
CfServiceInstance: "testInstance",
|
|
|
|
CfDeleteServiceKeys: true,
|
2020-02-10 15:53:12 +02:00
|
|
|
}
|
2020-08-10 11:08:34 +02:00
|
|
|
m := make(map[string]string)
|
|
|
|
m["cf service-keys testInstance"] = `line1
|
|
|
|
line2
|
|
|
|
line3
|
|
|
|
myServiceKey1
|
|
|
|
myServiceKey2
|
|
|
|
`
|
|
|
|
execRunner := mock.ExecMockRunner{
|
|
|
|
StdoutReturn: m,
|
2020-02-10 15:53:12 +02:00
|
|
|
}
|
2020-08-10 11:08:34 +02:00
|
|
|
cfUtils := cloudfoundry.CfUtilsMock{}
|
|
|
|
|
|
|
|
err := runCloudFoundryDeleteService(config, &execRunner, &cfUtils)
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, "cf", execRunner.Calls[0].Exec)
|
2020-02-27 13:11:22 +02:00
|
|
|
assert.Equal(t, "cf", execRunner.Calls[1].Exec)
|
|
|
|
assert.Equal(t, "cf", execRunner.Calls[2].Exec)
|
2020-03-05 16:35:43 +02:00
|
|
|
assert.Equal(t, "cf", execRunner.Calls[3].Exec)
|
2020-08-10 11:08:34 +02:00
|
|
|
assert.Equal(t, []string{"service-keys", "testInstance"}, execRunner.Calls[0].Params)
|
|
|
|
assert.Equal(t, []string{"delete-service-key", "testInstance", "myServiceKey1", "-f"}, execRunner.Calls[1].Params)
|
|
|
|
assert.Equal(t, []string{"delete-service-key", "testInstance", "myServiceKey2", "-f"}, execRunner.Calls[2].Params)
|
|
|
|
assert.Equal(t, []string{"delete-service", "testInstance", "-f"}, execRunner.Calls[3].Params)
|
2020-02-10 15:53:12 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|