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
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* 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>
2023-05-03 21:02:11 +05:00

51 lines
1.6 KiB
Go

//go:build unit
// +build unit
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)
}
})
}