Exemplo n.º 1
0
func (p *Provisioning) Create(ctx *app.CreateProvisioningContext) error {
	if p.state.InstanceExists(ctx.InstanceId) {
		return ctx.Conflict()
	}

	instance := repository.Instance{
		ID:             ctx.InstanceId,
		ServiceID:      ctx.ServiceId,
		PlanID:         ctx.PlanId,
		OrganizationID: ctx.OrganizationId,
		SpaceID:        ctx.SpaceId,
	}

	err := p.state.AddInstance(instance)
	if err != nil {
		return ctx.ServiceUnavailable()
	}

	return ctx.Created()
}
	BeforeEach(func() {
		state = new(fakes.FakeState)
		provisioningController = controllers.NewProvisioning(state)

		gctx := context.Background()
		req := http.Request{}
		responseWriter = httptest.NewRecorder()
		params := url.Values{}
		payload := map[string]string{}

		goaContext = goa.NewContext(gctx, &req, responseWriter, params, payload)
	})

	Describe("#Create", func() {
		var provisioningContext *app.CreateProvisioningContext

		BeforeEach(func() {
			var err error
			provisioningContext, err = app.NewCreateProvisioningContext(goaContext)
			Expect(err).ToNot(HaveOccurred())

			provisioningContext.InstanceId = "some-instance-id"
			provisioningContext.OrganizationId = "org-1"
			provisioningContext.SpaceId = "space-1"
			provisioningContext.ServiceId = "service-1"
			provisioningContext.PlanId = "plan-1"
		})

		Context("when all goes ok", func() {
			BeforeEach(func() {