1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/cloudFoundryDeleteService_test.go
Daniel Mieg 7ea5b09555
Improve tests for cf steps (#1875)
* Improve Tests for cf steps:
CreateServiceKey and Delete Service

* Fix CodeClimate issues

* Adapt descriptions

* Defer logout
2020-08-10 11:08:34 +02:00

48 lines
1.5 KiB
Go

package cmd
import (
"testing"
"github.com/SAP/jenkins-library/pkg/cloudfoundry"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/stretchr/testify/assert"
)
func TestCloudFoundryDeleteService(t *testing.T) {
t.Run("CF Delete Service : success case", func(t *testing.T) {
config := cloudFoundryDeleteServiceOptions{
CfAPIEndpoint: "https://api.endpoint.com",
CfOrg: "testOrg",
CfSpace: "testSpace",
Username: "testUser",
Password: "testPassword",
CfServiceInstance: "testInstance",
CfDeleteServiceKeys: true,
}
m := make(map[string]string)
m["cf service-keys testInstance"] = `line1
line2
line3
myServiceKey1
myServiceKey2
`
execRunner := mock.ExecMockRunner{
StdoutReturn: m,
}
cfUtils := cloudfoundry.CfUtilsMock{}
err := runCloudFoundryDeleteService(config, &execRunner, &cfUtils)
if assert.NoError(t, err) {
assert.Equal(t, "cf", execRunner.Calls[0].Exec)
assert.Equal(t, "cf", execRunner.Calls[1].Exec)
assert.Equal(t, "cf", execRunner.Calls[2].Exec)
assert.Equal(t, "cf", execRunner.Calls[3].Exec)
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)
}
})
}