Skip to content

fix: obscur error message when trying to use experimental features while the service is not configured for #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/api/v2/controllers_ledgers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
222 changes: 132 additions & 90 deletions test/e2e/api_ledgers_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,119 +21,161 @@ var _ = Context("Ledger engine tests", func() {
ctx = logging.TestingContext()
)

testServer := NewTestServer(func() Configuration {
return Configuration{
PostgresConfiguration: db.GetValue().ConnectionOptions(),
Output: GinkgoWriter,
Debug: debug,
NatsURL: natsServer.GetValue().ClientURL(),
ExperimentalFeatures: true,
}
})
When("creating a new ledger", func() {
var (
createLedgerRequest operations.V2CreateLedgerRequest
err error
)
BeforeEach(func() {
createLedgerRequest = operations.V2CreateLedgerRequest{
Ledger: "foo",
V2CreateLedgerRequest: components.V2CreateLedgerRequest{},
Context("without experimental features", func() {
testServer := NewTestServer(func() Configuration {
return Configuration{
PostgresConfiguration: db.GetValue().ConnectionOptions(),
Output: GinkgoWriter,
Debug: debug,
NatsURL: natsServer.GetValue().ClientURL(),
}
})
JustBeforeEach(func() {
err = CreateLedger(ctx, testServer.GetValue(), 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 = CreateLedger(ctx, testServer.GetValue(), 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 := NewTestServer(func() Configuration {
return Configuration{
PostgresConfiguration: db.GetValue().ConnectionOptions(),
Output: GinkgoWriter,
Debug: debug,
NatsURL: natsServer.GetValue().ClientURL(),
ExperimentalFeatures: true,
}
})
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() {
err := CreateLedger(ctx, testServer.GetValue(), operations.V2CreateLedgerRequest{
Ledger: createLedgerRequest.Ledger,
})
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumLedgerAlreadyExists)))
err = CreateLedger(ctx, testServer.GetValue(), 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() {
ledger, err := GetLedger(ctx, testServer.GetValue(), 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.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() {
err := CreateLedger(ctx, testServer.GetValue(), 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() {
ledger, err := GetLedger(ctx, testServer.GetValue(), operations.V2GetLedgerRequest{
Ledger: createLedgerRequest.Ledger,
})
Expect(err).To(BeNil())
Expect(ledger.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())
})
})
})
})
Expand Down
Loading