func (expectation transitionExpectation) driveFromState(allocationStore *allocationstore.AllocationStore, container executor.Container) { allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags) runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags) switch expectation.from { case "non-existent": case "reserved": _, err := allocationStore.Allocate(logger, &allocationRequest) Expect(err).NotTo(HaveOccurred()) case "initializing": _, err := allocationStore.Allocate(logger, &allocationRequest) Expect(err).NotTo(HaveOccurred()) err = allocationStore.Initialize(logger, &runReq) Expect(err).NotTo(HaveOccurred()) case "failed": _, err := allocationStore.Allocate(logger, &allocationRequest) Expect(err).NotTo(HaveOccurred()) err = allocationStore.Initialize(logger, &runReq) Expect(err).NotTo(HaveOccurred()) _, err = allocationStore.Fail(logger, container.Guid, "failure-reason") Expect(err).NotTo(HaveOccurred()) default: Fail("unknown 'from' state: " + expectation.from) } }
func (expectation transitionExpectation) transitionToState(allocationStore *allocationstore.AllocationStore, container executor.Container) error { switch expectation.to { case "reserve": allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags) _, err := allocationStore.Allocate(logger, &allocationRequest) return err case "initialize": runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags) return allocationStore.Initialize(logger, &runReq) case "fail": _, err := allocationStore.Fail(logger, container.Guid, "failure-reason") return err default: Fail("unknown 'to' state: " + expectation.to) return nil } }
Expect(err).To(Equal(executor.ErrContainerNotFound)) }) }) }) Describe("Fail", func() { var req executor.AllocationRequest BeforeEach(func() { resource := executor.NewResource(512, 512, "") req = executor.NewAllocationRequest("banana", &resource, nil) }) Context("when the container is not in the allocation store", func() { It("errors", func() { _, err := allocationStore.Fail(logger, req.Guid, "failure-response") Expect(err).To(HaveOccurred()) Expect(err).To(Equal(executor.ErrContainerNotFound)) Expect(fakeEventEmitter.EmitCallCount()).To(Equal(0)) }) }) Context("when the container is in the allocation store", func() { BeforeEach(func() { _, err := allocationStore.Allocate(logger, &req) Expect(err).NotTo(HaveOccurred()) }) It("it is marked as COMPLETED with failure reason", func() { emitCallCount := fakeEventEmitter.EmitCallCount()