Skip to content

Commit

Permalink
Enhancement on sample projects for validation annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Liujingfang1 committed May 15, 2018
1 parent 0724374 commit 9ca2f7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
// MemcachedSpec defines the desired state of Memcached
type MemcachedSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// +kubebuilder:validation:Maximum=100
// +kubebuilder:validation:Minimum=5
Size int32 `json:"size"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _ = Describe("Memcached", func() {
BeforeEach(func() {
instance = Memcached{}
instance.Name = "instance-1"
instance.Spec.Size = 50

expected = instance
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@ var _ = Describe("Memcached controller", func() {

// Create the instance
client = cs.MyappsV1alpha1().Memcacheds("default")

instance.Spec.Size = 1
_, err := client.Create(&instance)
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(MatchRegexp(".*spec.size in body should be greater than or equal to 5.*"))

instance.Spec.Size = 101
_, err = client.Create(&instance)
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(MatchRegexp(".*spec.size in body should be less than or equal to 100.*"))

instance.Spec.Size = 50
_, err = client.Create(&instance)
Expect(err).ShouldNot(HaveOccurred())

// Wait for reconcile to happen
Expand Down

0 comments on commit 9ca2f7a

Please sign in to comment.