diff --git a/internal/api/v2/controllers_ledgers_create.go b/internal/api/v2/controllers_ledgers_create.go index ac1ea9b2f..4b203a25c 100644 --- a/internal/api/v2/controllers_ledgers_create.go +++ b/internal/api/v2/controllers_ledgers_create.go @@ -35,7 +35,8 @@ func createLedger(systemController system.Controller) http.HandlerFunc { switch { case errors.Is(err, system.ErrInvalidLedgerConfiguration{}) || errors.Is(err, ledger.ErrInvalidLedgerName{}) || - errors.Is(err, ledger.ErrInvalidBucketName{}): + errors.Is(err, ledger.ErrInvalidBucketName{}) || + errors.Is(err, system.ErrExperimentalFeaturesDisabled): api.BadRequest(w, common.ErrValidation, err) case errors.Is(err, system.ErrBucketOutdated): api.BadRequest(w, common.ErrOutdatedSchema, err) diff --git a/test/e2e/api_ledgers_create_test.go b/test/e2e/api_ledgers_create_test.go index 980f11803..bf7c0e405 100644 --- a/test/e2e/api_ledgers_create_test.go +++ b/test/e2e/api_ledgers_create_test.go @@ -27,121 +27,164 @@ var _ = Context("Ledger engine tests", func() { natsURL = DeferMap(natsServer, (*natstesting.NatsServer).ClientURL) ) - testServer := ginkgo.DeferTestServer( - DeferMap(db, (*pgtesting.Database).ConnectionOptions), - testservice.WithInstruments( - testservice.NatsInstrumentation(natsURL), - testservice.DebugInstrumentation(debug), - testservice.OutputInstrumentation(GinkgoWriter), - ExperimentalFeaturesInstrumentation(), - ), - testservice.WithLogger(GinkgoT()), - ) - - When("creating a new ledger", func() { - var ( - createLedgerRequest operations.V2CreateLedgerRequest - err error + Context("without experimental features", func() { + testServer := ginkgo.DeferTestServer( + DeferMap(db, (*pgtesting.Database).ConnectionOptions), + testservice.WithInstruments( + testservice.NatsInstrumentation(natsURL), + testservice.DebugInstrumentation(debug), + testservice.OutputInstrumentation(GinkgoWriter), + ), + testservice.WithLogger(GinkgoT()), ) - BeforeEach(func() { - createLedgerRequest = operations.V2CreateLedgerRequest{ - Ledger: "foo", - V2CreateLedgerRequest: components.V2CreateLedgerRequest{}, - } - }) - JustBeforeEach(func(specContext SpecContext) { - _, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, createLedgerRequest) - }) - It("should be ok", func() { - Expect(err).To(BeNil()) - }) - Context("with specific features set", func() { + + When("creating a new ledger", func() { + var ( + createLedgerRequest operations.V2CreateLedgerRequest + err error + ) BeforeEach(func() { - createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet. - With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "DISABLED") + createLedgerRequest = operations.V2CreateLedgerRequest{ + Ledger: "foo", + V2CreateLedgerRequest: components.V2CreateLedgerRequest{}, + } + }) + JustBeforeEach(func(specContext SpecContext) { + _, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, createLedgerRequest) }) It("should be ok", func() { Expect(err).To(BeNil()) }) - }) - Context("with invalid feature configuration", func() { - BeforeEach(func() { - createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet. - With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "XXX") - }) - It("should fail", func() { - Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + Context("with specific features set", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet. + With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "DISABLED") + }) + It("should fail", func() { + Expect(err).NotTo(BeNil()) + Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + }) }) }) - Context("with invalid feature name", func() { + }) + + Context("with experimental features", func() { + testServer := ginkgo.DeferTestServer( + DeferMap(db, (*pgtesting.Database).ConnectionOptions), + testservice.WithInstruments( + testservice.NatsInstrumentation(natsURL), + testservice.DebugInstrumentation(debug), + testservice.OutputInstrumentation(GinkgoWriter), + ExperimentalFeaturesInstrumentation(), + ), + testservice.WithLogger(GinkgoT()), + ) + + When("creating a new ledger", func() { + var ( + createLedgerRequest operations.V2CreateLedgerRequest + err error + ) BeforeEach(func() { - createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet. - With("foo", "XXX") - }) - It("should fail", func() { - Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + createLedgerRequest = operations.V2CreateLedgerRequest{ + Ledger: "foo", + V2CreateLedgerRequest: components.V2CreateLedgerRequest{}, + } }) - }) - Context("trying to create another ledger with the same name", func() { JustBeforeEach(func(specContext SpecContext) { - _, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{ - Ledger: createLedgerRequest.Ledger, - }) - Expect(err).NotTo(BeNil()) - Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumLedgerAlreadyExists))) + _, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, createLedgerRequest) }) - It("should fail", func() {}) - }) - Context("bucket naming convention depends on the database 63 bytes length (pg constraint)", func() { - BeforeEach(func() { - createLedgerRequest.V2CreateLedgerRequest.Bucket = pointer.For(strings.Repeat("a", 64)) + It("should be ok", func() { + Expect(err).To(BeNil()) }) - It("should fail with > 63 characters in ledger or bucket name", func() { - Expect(err).To(HaveOccurred()) + Context("with specific features set", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet. + With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "DISABLED") + }) + It("should be ok", func() { + Expect(err).To(BeNil()) + }) }) - }) - Context("With metadata", func() { - BeforeEach(func() { - createLedgerRequest.V2CreateLedgerRequest.Metadata = map[string]string{ - "foo": "bar", - } + Context("with invalid feature configuration", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet. + With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "XXX") + }) + It("should fail", func() { + Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + }) }) - It("Should be ok", func(specContext SpecContext) { - ledger, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.GetLedger(ctx, operations.V2GetLedgerRequest{ - Ledger: createLedgerRequest.Ledger, + Context("with invalid feature name", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet. + With("foo", "XXX") + }) + It("should fail", func() { + Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) }) - Expect(err).To(BeNil()) - Expect(ledger.V2GetLedgerResponse.Data.Metadata).To(Equal(createLedgerRequest.V2CreateLedgerRequest.Metadata)) }) - }) - Context("with invalid ledger name", func() { - BeforeEach(func() { - createLedgerRequest.Ledger = "invalid\\name\\contains\\some\\backslash" + Context("trying to create another ledger with the same name", func() { + JustBeforeEach(func(specContext SpecContext) { + _, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{ + Ledger: createLedgerRequest.Ledger, + }) + Expect(err).NotTo(BeNil()) + Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumLedgerAlreadyExists))) + }) + It("should fail", func() {}) }) - It("should fail", func() { - Expect(err).NotTo(BeNil()) - Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + Context("bucket naming convention depends on the database 63 bytes length (pg constraint)", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest.Bucket = pointer.For(strings.Repeat("a", 64)) + }) + It("should fail with > 63 characters in ledger or bucket name", func() { + Expect(err).To(HaveOccurred()) + }) }) - }) - Context("with invalid bucket name", func() { - BeforeEach(func() { - createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{ - Bucket: pointer.For("invalid\\name\\contains\\some\\backslash"), - } + Context("With metadata", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest.Metadata = map[string]string{ + "foo": "bar", + } + }) + It("Should be ok", func(specContext SpecContext) { + ledger, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.GetLedger(ctx, operations.V2GetLedgerRequest{ + Ledger: createLedgerRequest.Ledger, + }) + Expect(err).To(BeNil()) + Expect(ledger.V2GetLedgerResponse.Data.Metadata).To(Equal(createLedgerRequest.V2CreateLedgerRequest.Metadata)) + }) }) - It("should fail", func() { - Expect(err).NotTo(BeNil()) - Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + Context("with invalid ledger name", func() { + BeforeEach(func() { + createLedgerRequest.Ledger = "invalid\\name\\contains\\some\\backslash" + }) + It("should fail", func() { + Expect(err).NotTo(BeNil()) + Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + }) }) - }) - Context("on alternate bucket", func() { - BeforeEach(func() { - createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{ - Bucket: pointer.For("bucket0"), - } + Context("with invalid bucket name", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{ + Bucket: pointer.For("invalid\\name\\contains\\some\\backslash"), + } + }) + It("should fail", func() { + Expect(err).NotTo(BeNil()) + Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation))) + }) }) - It("should be ok", func() { - Expect(err).To(BeNil()) + Context("on alternate bucket", func() { + BeforeEach(func() { + createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{ + Bucket: pointer.For("bucket0"), + } + }) + It("should be ok", func() { + Expect(err).To(BeNil()) + }) }) }) })