Skip to content

Commit 5b87e7b

Browse files
committed
feat: move test to rawconfig
Signed-off-by: Meng JiaFeng <[email protected]>
1 parent 4635fef commit 5b87e7b

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

internal/pkg/configmanager/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (a *app) getTools(vars map[string]any, templateMap map[string]string) (Tool
3535

3636
// get ci/cd pipelineTemplates
3737
appVars := a.Spec.merge(vars)
38-
tools, err := a.generateCICDToolsFromAppConfig(templateMap, appVars)
38+
tools, err := a.generateCICDTools(templateMap, appVars)
3939
if err != nil {
4040
return nil, fmt.Errorf("app[%s] get pipeline tools failed: %w", a.Name, err)
4141
}
@@ -49,7 +49,7 @@ func (a *app) getTools(vars map[string]any, templateMap map[string]string) (Tool
4949
}
5050

5151
// getAppPipelineTool generate ci/cd tools from app config
52-
func (a *app) generateCICDToolsFromAppConfig(templateMap map[string]string, appVars map[string]any) (Tools, error) {
52+
func (a *app) generateCICDTools(templateMap map[string]string, appVars map[string]any) (Tools, error) {
5353
allPipelineRaw := append(a.CIRawConfigs, a.CDRawConfigs...)
5454
var tools Tools
5555
for _, p := range allPipelineRaw {

internal/pkg/configmanager/app_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,31 @@ var _ = Describe("app struct", func() {
5353
})
5454
})
5555
})
56+
57+
Context("generateCICDTools method", func() {
58+
When("template type not exist", func() {
59+
BeforeEach(func() {
60+
a = &app{
61+
Repo: &scm.SCMInfo{
62+
CloneURL: "http://test.com/test/test_app",
63+
},
64+
CIRawConfigs: []pipelineRaw{
65+
{
66+
Type: "template",
67+
TemplateName: "not_valid",
68+
},
69+
},
70+
}
71+
})
72+
It("should return error", func() {
73+
templateMap = map[string]string{
74+
"not_valid": `
75+
name: not_valid,
76+
type: not_valid`}
77+
_, err := a.generateCICDTools(templateMap, vars)
78+
Expect(err).Should(HaveOccurred())
79+
Expect(err.Error()).Should(ContainSubstring("pipeline type [not_valid] not supported for now"))
80+
})
81+
})
82+
})
5683
})

internal/pkg/configmanager/rawconfig_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,22 @@ var _ = Describe("rawConfig struct", func() {
196196
})
197197
})
198198
})
199+
200+
Context("getVars method", func() {
201+
BeforeEach(func() {
202+
r = &rawConfig{
203+
vars: []byte(`---
204+
foo1: bar1
205+
foo2: 123
206+
foo3: bar3`)}
207+
})
208+
It("should works fine", func() {
209+
varMap, err := r.getVars()
210+
Expect(err).NotTo(HaveOccurred())
211+
Expect(varMap).NotTo(BeNil())
212+
Expect(len(varMap)).To(Equal(3))
213+
Expect(varMap["foo1"]).To(Equal(interface{}("bar1")))
214+
Expect(varMap["foo2"]).To(Equal(interface{}(123)))
215+
})
216+
})
199217
})

internal/pkg/configmanager/variables_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,3 @@ var _ = Describe("renderConfigWithVariables", func() {
2424
})
2525
})
2626
})
27-
28-
// var _ = Describe("getVarsFromConfigFile", func() {
29-
// const configFile = `---
30-
// foo: bar
31-
// vars:
32-
// foo1: bar1
33-
// foo2: 123
34-
// foo3: bar3
35-
// `
36-
// When("get vars from config file", func() {
37-
// It("should works fine", func() {
38-
// varMap, err := getVarsFromConfigFile([]byte(configFile))
39-
// Expect(err).NotTo(HaveOccurred())
40-
// Expect(varMap).NotTo(BeNil())
41-
// Expect(len(varMap)).To(Equal(2))
42-
// Expect(varMap["foo1"]).To(Equal(interface{}("bar1")))
43-
// Expect(varMap["foo2"]).To(Equal(interface{}(123)))
44-
// })
45-
// })
46-
// })

0 commit comments

Comments
 (0)