Skip to content

Commit 91c963f

Browse files
Added tests for init.go
1 parent 88afbd6 commit 91c963f

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

pkg/quarkus/v1alpha/init_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2021 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1
16+
17+
import (
18+
. "github.com/onsi/ginkgo"
19+
. "github.com/onsi/gomega"
20+
"github.com/spf13/pflag"
21+
"sigs.k8s.io/kubebuilder/v3/pkg/config"
22+
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
23+
)
24+
25+
var _ = Describe("v1", func() {
26+
successInitSubcommand := &initSubcommand{
27+
domain: "testDomain",
28+
projectName: "test-123",
29+
}
30+
31+
failureInitSubcommand := &initSubcommand{
32+
domain: "testDomain",
33+
projectName: "?&fail&?",
34+
commandName: "failureTest",
35+
}
36+
37+
Describe("UpdateMetadata", func() {
38+
testCliMetadata := plugin.CLIMetadata{CommandName: "TestCommand"}
39+
testSubcommandMetadata := plugin.SubcommandMetadata{}
40+
41+
It("Check command name inequality pre function call", func() {
42+
Expect(failureInitSubcommand.commandName).NotTo(Equal(testCliMetadata.CommandName))
43+
})
44+
45+
successInitSubcommand.UpdateMetadata(testCliMetadata, &testSubcommandMetadata)
46+
47+
It("Check command name equality post function call", func() {
48+
Expect(successInitSubcommand.commandName, testCliMetadata.CommandName)
49+
})
50+
})
51+
52+
Describe("BindFlags", func() {
53+
flagTest := pflag.NewFlagSet("testFlag", -1)
54+
successInitSubcommand.BindFlags(flagTest)
55+
56+
It("should set SortFlags to false", func() {
57+
Expect(flagTest.SortFlags).To(BeFalse())
58+
})
59+
60+
It("should set domain to my.domain", func() {
61+
Expect(successInitSubcommand.domain, "my.domain")
62+
})
63+
64+
It("should set projectName to an empty string", func() {
65+
Expect(successInitSubcommand.projectName, "")
66+
})
67+
68+
It("should set group to an empty string", func() {
69+
Expect(successInitSubcommand.group, "")
70+
})
71+
72+
It("should set version to an empty string", func() {
73+
Expect(successInitSubcommand.version, "")
74+
})
75+
76+
It("should set kind to an empty string", func() {
77+
Expect(successInitSubcommand.kind, "")
78+
})
79+
})
80+
81+
Describe("InjectConfig", func() {
82+
testConfig, _ := config.New(config.Version{Number: 3})
83+
84+
It("should error", func() {
85+
Expect(failureInitSubcommand.InjectConfig(testConfig)).To(HaveOccurred())
86+
})
87+
88+
It("should return nil", func() {
89+
Expect(successInitSubcommand.InjectConfig(testConfig)).To(BeNil())
90+
})
91+
})
92+
93+
Describe("Validate", func() {
94+
It("should return nil", func() {
95+
Expect(successInitSubcommand.Validate()).To(BeNil())
96+
})
97+
})
98+
99+
Describe("PostScaffold", func() {
100+
It("should return nil", func() {
101+
Expect(successInitSubcommand.PostScaffold()).To(BeNil())
102+
})
103+
})
104+
})

pkg/quarkus/v1alpha/v1_suite_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2021 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1
16+
17+
import (
18+
"testing"
19+
20+
. "github.com/onsi/ginkgo"
21+
. "github.com/onsi/gomega"
22+
)
23+
24+
func TestUtil(t *testing.T) {
25+
RegisterFailHandler(Fail)
26+
RunSpecs(t, "v1")
27+
}

0 commit comments

Comments
 (0)