From 2763220da59b5b04ceee8de164ee320ec6f4dbba Mon Sep 17 00:00:00 2001 From: George Blue Date: Thu, 28 Oct 2021 10:53:20 +0100 Subject: [PATCH] test: print error when create/update service fails When running CF CLI v8 with --wait flag, we don't see the error from the broker if the command fails. [#177720203](https://www.pivotaltracker.com/story/show/177720203) --- acceptance-tests/helpers/service.go | 60 ++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/acceptance-tests/helpers/service.go b/acceptance-tests/helpers/service.go index 14981647b..af1e13b5b 100644 --- a/acceptance-tests/helpers/service.go +++ b/acceptance-tests/helpers/service.go @@ -39,17 +39,36 @@ func CreateServiceInBroker(offering, plan, broker string, parameters ...interfac } func CreateService(offering, plan string, parameters ...interface{}) ServiceInstance { + switch cfVersion() { + case cfVersionV8: + return createServiceWithWait(offering, plan, parameters...) + default: + return createServiceWithPoll(offering, plan, parameters...) + } +} + +func createServiceWithWait(offering, plan string, parameters ...interface{}) ServiceInstance { name := RandomName(offering, plan) - createCommandTimeout := 5 * time.Minute // MASB is slow to start creation - args := []string{"create-service", offering, plan, name} - if cfVersion() == cfVersionV8 { - args = append(args, "--wait") - createCommandTimeout = time.Hour + args := append([]string{"create-service", offering, plan, name, "--wait"}, serviceParameters(parameters)...) + + session := StartCF(args...) + Eventually(session, time.Hour).Should(Exit(0), func() string { + out, _ := CF("service", name) + return out + }) + + return ServiceInstance{ + name: name, + offering: offering, } - args = append(args, serviceParameters(parameters)...) +} + +func createServiceWithPoll(offering, plan string, parameters ...interface{}) ServiceInstance { + name := RandomName(offering, plan) + args := append([]string{"create-service", offering, plan, name}, serviceParameters(parameters)...) session := StartCF(args...) - Eventually(session, createCommandTimeout).Should(Exit(0)) + Eventually(session, 5*time.Minute).Should(Exit(0)) Eventually(func() string { out, _ := CF("service", name) @@ -64,16 +83,29 @@ func CreateService(offering, plan string, parameters ...interface{}) ServiceInst } func (s ServiceInstance) UpdateService(parameters ...string) { - createCommandTimeout := time.Minute - args := []string{"update-service", s.name} - if cfVersion() == cfVersionV8 { - args = append(args, "--wait") - createCommandTimeout = time.Hour + switch cfVersion() { + case cfVersionV8: + s.updateServiceWithWait(parameters...) + default: + s.updateServiceWithPoll(parameters...) } - args = append(args, parameters...) +} + +func (s ServiceInstance) updateServiceWithWait(parameters ...string) { + args := append([]string{"update-service", s.name, "--wait"}, parameters...) session := StartCF(args...) - Eventually(session, createCommandTimeout).Should(Exit(0)) + Eventually(session, time.Hour).Should(Exit(0), func() string { + out, _ := CF("service", s.name) + return out + }) +} + +func (s ServiceInstance) updateServiceWithPoll(parameters ...string) { + args := append([]string{"update-service", s.name}, parameters...) + + session := StartCF(args...) + Eventually(session, 5*time.Minute).Should(Exit(0)) Eventually(func() string { out, _ := CF("service", s.name)