File tree 3 files changed +51
-5
lines changed
pkg/quarkus/v1alpha/scaffolds/internal/templates
3 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -39,12 +39,12 @@ func (f *OperatorFile) SetTemplateDefaults() error {
39
39
return fmt .Errorf ("invalid operator name" )
40
40
}
41
41
42
+ if strings .HasSuffix (f .OperatorName , "Operator" ) {
43
+ f .OperatorName = strings .TrimSuffix (f .OperatorName , "Operator" )
44
+ }
45
+
42
46
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 ))
48
48
}
49
49
50
50
f .TemplateBody = operatorTemplate
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments