. "github.com/vito/cmdtest/matchers"

	. "github.com/peterellisjones/cf-acceptance-tests/helpers"
	"github.com/peterellisjones/cf-acceptance-tests/services/helpers"
	. "github.com/peterellisjones/cf-test-helpers/cf"
	"github.com/peterellisjones/cf-test-helpers/generator"
)

var _ = Describe("Service Broker Lifecycle", func() {
	var broker helpers.ServiceBroker

	BeforeEach(func() {
		helpers.LoginAsAdmin()
		broker = helpers.NewServiceBroker(generator.RandomName(), NewAssets().ServiceBroker)
		broker.Push()
		broker.Configure()
	})

	AfterEach(func() {
		helpers.LoginAsUser()
	})

	It("confirms correct behavior in the lifecycle of a service broker", func() {
		defer helpers.Recover() // Catches panic thrown by Require expectations

		// Adding the service broker
		helpers.Require(Cf("create-service-broker", broker.Name, "username", "password", AppUri(broker.Name, "", LoadConfig().AppsDomain))).To(ExitWithTimeout(0, 10*time.Second))
		Expect(Cf("service-brokers")).To(Say(broker.Name))

		// Confirming the plans are not yet public
		session := Cf("marketplace")