Skip to content

Commit

Permalink
Rewrite unit tests in internal/kubebuilder/machinery
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Stroczynski <estroczy@redhat.com>
  • Loading branch information
varshaprasad96 and Eric Stroczynski committed Dec 4, 2020
1 parent a6b7b56 commit 5a5c4fc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 67 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@ sigs.k8s.io/controller-runtime v0.7.0-alpha.6 h1:ieFqEijQyDEZVIGwI5sYkk7VTa8Itim
sigs.k8s.io/controller-runtime v0.7.0-alpha.6/go.mod h1:03b1n6EtlDvuBPPEOHadJUusruwLWgoT4BDCybMibnA=
sigs.k8s.io/controller-tools v0.3.0 h1:y3YD99XOyWaXkiF1kd41uRvfp/64teWcrEZFuHxPhJ4=
sigs.k8s.io/controller-tools v0.3.0/go.mod h1:enhtKGfxZD1GFEoMgP8Fdbu+uKQ/cq1/WGJhdVChfvI=
sigs.k8s.io/kubebuilder v1.0.8 h1:XYctSbuOICM9z1Ok0GIWChc1cj90EEEczeJQnb7ZPf0=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201111001842-c158f4fa4207 h1:JtlaBrtWymJbh6ea+TJUZkzBb0x0dMKV+P0+ZPaldxk=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201111001842-c158f4fa4207/go.mod h1:J/D/179LBZhQOhRvmMRNbje/Bk+PjbN0/fzUupmO7+U=
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
Expand Down
6 changes: 0 additions & 6 deletions internal/kubebuilder/machinery/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ package machinery
import (
"errors"
"path/filepath"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)

func TestErrors(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Error suite")
}

var _ = Describe("Errors", func() {
var (
path = filepath.Join("path", "to", "file")
Expand Down
25 changes: 25 additions & 0 deletions internal/kubebuilder/machinery/machinery_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package machinery

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestScaffold(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Machinery Suite")
}
82 changes: 21 additions & 61 deletions internal/kubebuilder/machinery/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package machinery
import (
"bytes"
"errors"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
Expand All @@ -28,11 +27,6 @@ import (
"github.com/operator-framework/operator-sdk/internal/kubebuilder/filesystem"
)

func TestScaffold(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Scaffold suite")
}

var _ = Describe("Scaffold", func() {
Describe("NewScaffold", func() {
var (
Expand All @@ -41,61 +35,27 @@ var _ = Describe("Scaffold", func() {
ok bool
)

Context("when using no plugins", func() {
BeforeEach(func() {
si = NewScaffold()
s, ok = si.(*scaffold)
})

It("should be a scaffold instance", func() {
Expect(ok).To(BeTrue())
})

It("should not have a nil fs", func() {
Expect(s.fs).NotTo(BeNil())
})

It("should not have any plugin", func() {
Expect(len(s.plugins)).To(Equal(0))
})
})

Context("when using one plugin", func() {
BeforeEach(func() {
si = NewScaffold(fakePlugin{})
s, ok = si.(*scaffold)
})

It("should be a scaffold instance", func() {
Expect(ok).To(BeTrue())
})

It("should not have a nil fs", func() {
Expect(s.fs).NotTo(BeNil())
})

It("should have one plugin", func() {
Expect(len(s.plugins)).To(Equal(1))
})
})

Context("when using several plugins", func() {
BeforeEach(func() {
si = NewScaffold(fakePlugin{}, fakePlugin{}, fakePlugin{})
s, ok = si.(*scaffold)
})

It("should be a scaffold instance", func() {
Expect(ok).To(BeTrue())
})

It("should not have a nil fs", func() {
Expect(s.fs).NotTo(BeNil())
})

It("should have several plugins", func() {
Expect(len(s.plugins)).To(Equal(3))
})
It("should create a valid scaffold", func() {
By("passing no plugins")
si = NewScaffold()
s, ok = si.(*scaffold)
Expect(ok).To(BeTrue())
Expect(s.fs).NotTo(BeNil())
Expect(len(s.plugins)).To(Equal(0))

By("passing one plugin")
si = NewScaffold(fakePlugin{})
s, ok = si.(*scaffold)
Expect(ok).To(BeTrue())
Expect(s.fs).NotTo(BeNil())
Expect(len(s.plugins)).To(Equal(1))

By("passing multiple plugins")
si = NewScaffold(fakePlugin{}, fakePlugin{}, fakePlugin{})
s, ok = si.(*scaffold)
Expect(ok).To(BeTrue())
Expect(s.fs).NotTo(BeNil())
Expect(len(s.plugins)).To(Equal(3))
})
})

Expand Down

0 comments on commit 5a5c4fc

Please sign in to comment.