github.com/jaylevin/jenkins-library@v1.230.4/cmd/cloudFoundryDeleteService_test.go (about) 1 package cmd 2 3 import ( 4 "testing" 5 6 "github.com/SAP/jenkins-library/pkg/cloudfoundry" 7 "github.com/SAP/jenkins-library/pkg/mock" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestCloudFoundryDeleteService(t *testing.T) { 12 13 t.Run("CF Delete Service : success case", func(t *testing.T) { 14 config := cloudFoundryDeleteServiceOptions{ 15 CfAPIEndpoint: "https://api.endpoint.com", 16 CfOrg: "testOrg", 17 CfSpace: "testSpace", 18 Username: "testUser", 19 Password: "testPassword", 20 CfServiceInstance: "testInstance", 21 CfDeleteServiceKeys: true, 22 } 23 m := make(map[string]string) 24 m["cf service-keys testInstance"] = `line1 25 line2 26 line3 27 myServiceKey1 28 myServiceKey2 29 ` 30 execRunner := mock.ExecMockRunner{ 31 StdoutReturn: m, 32 } 33 cfUtils := cloudfoundry.CfUtilsMock{} 34 35 err := runCloudFoundryDeleteService(config, &execRunner, &cfUtils) 36 if assert.NoError(t, err) { 37 assert.Equal(t, "cf", execRunner.Calls[0].Exec) 38 assert.Equal(t, "cf", execRunner.Calls[1].Exec) 39 assert.Equal(t, "cf", execRunner.Calls[2].Exec) 40 assert.Equal(t, "cf", execRunner.Calls[3].Exec) 41 assert.Equal(t, []string{"service-keys", "testInstance"}, execRunner.Calls[0].Params) 42 assert.Equal(t, []string{"delete-service-key", "testInstance", "myServiceKey1", "-f"}, execRunner.Calls[1].Params) 43 assert.Equal(t, []string{"delete-service-key", "testInstance", "myServiceKey2", "-f"}, execRunner.Calls[2].Params) 44 assert.Equal(t, []string{"delete-service", "testInstance", "-f"}, execRunner.Calls[3].Params) 45 } 46 }) 47 }