Skip to content

Commit

Permalink
Using common.DATABASE_TYPE_POSTGRES, deleted NDB validation, refactor…
Browse files Browse the repository at this point in the history
…ed tests by removing list
  • Loading branch information
mazin-s committed Sep 27, 2023
1 parent 8a71398 commit 3c4edbf
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 215 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/database_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func instanceSpecValidatorForCreate(instance *Instance, allErrs field.ErrorList,
}

/* Checks if configured additional arguments are invalid */
func checkIfAdditionalArgumentsInvalid(typ string, additionalArguments map[string]string) (bool, map[string]bool) {
func isAdditionalArgumentsInvalid(typ string, additionalArguments map[string]string) (bool, map[string]bool) {
var allowedAdditionalArguments map[string]bool
switch typ {
case common.DATABASE_TYPE_MYSQL:
Expand All @@ -248,7 +248,7 @@ func checkIfAdditionalArgumentsInvalid(typ string, additionalArguments map[strin
/* Validates additionalaction arguments */
func instanceSpecAdditionalArgumentsValidator(instance *Instance, allErrs field.ErrorList, instancePath *field.Path) field.ErrorList {
additionalArgumentsPath := instancePath.Child("additionalArguments")
isInvalidTypeDetails, allowedTypeDetails := checkIfAdditionalArgumentsInvalid(instance.Type, instance.AdditionalArguments)
isInvalidTypeDetails, allowedTypeDetails := isAdditionalArgumentsInvalid(instance.Type, instance.AdditionalArguments)
if isInvalidTypeDetails {
allErrs = append(
allErrs,
Expand Down
22 changes: 11 additions & 11 deletions api/v1alpha1/webhook_suite_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ndbSpecMissing() *Database {
DatabaseInstanceName: "db-instance-name",
CredentialSecret: "db-instance-secret",
Size: 10,
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
TimeZone: "UTC",
},
},
Expand All @@ -42,7 +42,7 @@ func ndbClusterIdMissing() *Database {
DatabaseInstanceName: "db-instance-name",
CredentialSecret: "db-instance-secret",
Size: 10,
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
TimeZone: "UTC",
},
},
Expand All @@ -66,7 +66,7 @@ func ndbCredentialSecretMissing() *Database {
DatabaseInstanceName: "db-instance-name",
CredentialSecret: "db-instance-secret",
Size: 10,
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
TimeZone: "UTC",
},
},
Expand All @@ -90,7 +90,7 @@ func ndbServerURLMissing() *Database {
DatabaseInstanceName: "db-instance-name",
CredentialSecret: "db-instance-secret",
Size: 10,
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
TimeZone: "UTC",
},
},
Expand All @@ -115,7 +115,7 @@ func dbInstanceNameMissing() *Database {
CredentialSecret: "db-instance-secret",
Size: 10,
TimeZone: "UTC",
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
},
},
}
Expand All @@ -140,7 +140,7 @@ func dbDescriptionNotSpecified(db string) *Database {
CredentialSecret: "db-instance-secret",
Size: 10,
TimeZone: "UTC",
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
},
},
}
Expand All @@ -165,7 +165,7 @@ func dbDatabaseNamesNotSpecified(db string) *Database {
CredentialSecret: "db-instance-secret",
Size: 10,
TimeZone: "UTC",
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
},
},
}
Expand All @@ -189,7 +189,7 @@ func dbCredentialSecretMissing() *Database {
DatabaseInstanceName: "db-instance-name",
Size: 10,
TimeZone: "UTC",
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
},
},
}
Expand All @@ -214,7 +214,7 @@ func dbSizeLessThan10() *Database {
CredentialSecret: "db-instance-secret",
Size: 1,
TimeZone: "UTC",
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
},
},
}
Expand All @@ -238,7 +238,7 @@ func dbTimeZoneNotSpecified() *Database {
DatabaseInstanceName: "db-instance-name",
CredentialSecret: "db-instance-secret",
Size: 1,
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
},
},
}
Expand Down Expand Up @@ -309,7 +309,7 @@ func dbTimeMachineNotSpecified(db string) *Database {
DatabaseInstanceName: "db-instance-name",
CredentialSecret: "db-instance-secret",
Size: 10,
Type: common.DATABASE_ENGINE_TYPE_POSTGRES,
Type: common.DATABASE_TYPE_POSTGRES,
},
},
}
Expand Down
43 changes: 0 additions & 43 deletions api/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,49 +141,6 @@ var _ = AfterEach(func() {

var _ = Describe("Webhook Tests", func() {

Describe("NDB Validation", func() {
When("Spec field is missing", func() {
It("Throws an rrror", func() {
database := ndbSpecMissing()
err := k8sClient.Create(context.Background(), database)
Expect(err).To(HaveOccurred())
errMsg := err.(*errors.StatusError).ErrStatus.Message
Expect(errMsg).To(ContainSubstring("NDB server spec must be provided!"))
})
})

When("'clusterId' is missing", func() {
It("Throws an error", func() {
database := ndbClusterIdMissing()
err := k8sClient.Create(context.Background(), database)
Expect(err).To(HaveOccurred())
errMsg := err.(*errors.StatusError).ErrStatus.Message
Expect(errMsg).To(ContainSubstring("NDB ClusterId must be provided and be a valid UUID!"))
})
})

When("'credentialSecret' is missing", func() {
It("Throws an error", func() {
database := ndbCredentialSecretMissing()
err := k8sClient.Create(context.Background(), database)
Expect(err).To(HaveOccurred())
errMsg := err.(*errors.StatusError).ErrStatus.Message
Expect(errMsg).To(ContainSubstring("NDB CredentialSecret must be provided!"))

})
})

When("'server' URL is missing", func() {
It("Throws an error", func() {
database := ndbServerURLMissing()
err := k8sClient.Create(context.Background(), database)
Expect(err).To(HaveOccurred())
errMsg := err.(*errors.StatusError).ErrStatus.Message
Expect(errMsg).To(ContainSubstring("NDB Server URL must be provided and be a valid URL!"))
})
})
})

Describe("DB Validation", func() {
When("'databaseInstanceName' is missing", func() {
It("Throws an error", func() {
Expand Down
Loading

0 comments on commit 3c4edbf

Please sign in to comment.