Skip to content

Commit 8303c38

Browse files
authored
Fix stutter when project name includes "operator" (#12)
Signed-off-by: jesus m. rodriguez <[email protected]>
1 parent b8f7ac1 commit 8303c38

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

pkg/quarkus/v1alpha/scaffolds/internal/templates/operatorfile.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func (f *OperatorFile) SetTemplateDefaults() error {
3939
return fmt.Errorf("invalid operator name")
4040
}
4141

42+
if strings.HasSuffix(f.OperatorName, "Operator") {
43+
f.OperatorName = strings.TrimSuffix(f.OperatorName, "Operator")
44+
}
45+
4246
if f.Path == "" {
43-
if strings.HasSuffix(strings.ToLower(f.OperatorName), "operator") {
44-
f.Path = util.PrependJavaPath(f.OperatorName+".java", util.AsPath(f.Package))
45-
} else {
46-
f.Path = util.PrependJavaPath(f.OperatorName+"Operator.java", util.AsPath(f.Package))
47-
}
47+
f.Path = util.PrependJavaPath(f.OperatorName+"Operator.java", util.AsPath(f.Package))
4848
}
4949

5050
f.TemplateBody = operatorTemplate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package templates
2+
3+
import (
4+
"bytes"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
9+
"text/template"
10+
)
11+
12+
var _ = Describe("operatorfile", func() {
13+
14+
Describe("SetTemplateDefaults", func() {
15+
It("Should not stutter operator", func() {
16+
17+
of := OperatorFile{
18+
OperatorName: "MemcachedQuarkusOperator",
19+
}
20+
21+
err := of.SetTemplateDefaults()
22+
Expect(err).ToNot(HaveOccurred())
23+
Expect(of.Path).To(HaveSuffix("MemcachedQuarkusOperator.java"))
24+
25+
tmpl, err := template.New("operatorfile").Parse(of.TemplateBody)
26+
Expect(err).ToNot(HaveOccurred())
27+
buf := new(bytes.Buffer)
28+
err = tmpl.Execute(buf, of)
29+
Expect(err).ToNot(HaveOccurred())
30+
Expect(buf.String()).To(ContainSubstring("public class MemcachedQuarkusOperator "))
31+
})
32+
})
33+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package templates
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestTemplates(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "operatorfile")
13+
}

0 commit comments

Comments
 (0)