Skip to content

Commit 61c9bf1

Browse files
committed
fix: change func name
Signed-off-by: Meng JiaFeng <jiafeng.meng@merico.dev>
1 parent 36c6297 commit 61c9bf1

11 files changed

Lines changed: 61 additions & 61 deletions

File tree

internal/pkg/configmanager/app.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type (
2525
}
2626
)
2727

28-
// getAppTools return app tools
29-
func getAppTools(appStr string, globalVars map[string]any, templateMap map[string]string) (Tools, error) {
28+
// getToolsFromApp return app tools
29+
func getToolsFromApp(appStr string, globalVars map[string]any, templateMap map[string]string) (Tools, error) {
3030
//1. render appStr with globalVars
3131
appRenderStr, err := renderConfigWithVariables(appStr, globalVars)
3232
if err != nil {
@@ -39,14 +39,14 @@ func getAppTools(appStr string, globalVars map[string]any, templateMap map[strin
3939
return nil, fmt.Errorf("app parse yaml failed: %w", err)
4040
}
4141
rawData.setDefault()
42-
appVars := mapz.MergeMaps(globalVars, rawData.Spec)
42+
appVars := mapz.Merge(globalVars, rawData.Spec)
4343
// 3. generate app repo and tempalte repo from scmInfo
4444
repoScaffoldingTool, err := rawData.getRepoTemplateTool(appVars)
4545
if err != nil {
4646
return nil, fmt.Errorf("app[%s] get repo failed: %w", rawData.Name, err)
4747
}
4848
// 4. get ci/cd pipelineTemplates
49-
tools, err := rawData.getPipelineTools(templateMap, appVars)
49+
tools, err := rawData.generateCICDToolsFromAppConfig(templateMap, appVars)
5050
if err != nil {
5151
return nil, fmt.Errorf("app[%s] get pipeline tools failed: %w", rawData.Name, err)
5252
}
@@ -57,7 +57,7 @@ func getAppTools(appStr string, globalVars map[string]any, templateMap map[strin
5757
}
5858

5959
// getAppPipelineTool generate ci/cd tools from app config
60-
func (a *appRaw) getPipelineTools(templateMap map[string]string, appVars map[string]any) (Tools, error) {
60+
func (a *appRaw) generateCICDToolsFromAppConfig(templateMap map[string]string, appVars map[string]any) (Tools, error) {
6161
allPipelineRaw := append(a.CIRawConfigs, a.CDRawConfigs...)
6262
var tools Tools
6363
for _, p := range allPipelineRaw {
@@ -69,7 +69,7 @@ func (a *appRaw) getPipelineTools(templateMap map[string]string, appVars map[str
6969
if err != nil {
7070
return nil, err
7171
}
72-
pipelineTool.DependsOn = a.getRepoTemplateDepends()
72+
pipelineTool.DependsOn = a.getRepoTemplateDependants()
7373
tools = append(tools, *pipelineTool)
7474
}
7575
return tools, nil
@@ -108,7 +108,7 @@ func (a *appRaw) setDefault() {
108108
}
109109

110110
// since all plugin depends on code is deployed, get dependsOn for repoTemplate
111-
func (a *appRaw) getRepoTemplateDepends() []string {
111+
func (a *appRaw) getRepoTemplateDependants() []string {
112112
var dependsOn []string
113113
// if a.RepoTemplate is configured, pipeline need to wait reposcaffolding finished
114114
if a.RepoTemplate != nil {

internal/pkg/configmanager/app_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/devstream-io/devstream/pkg/util/scm"
88
)
99

10-
var _ = Describe("getAppTools func", func() {
10+
var _ = Describe("getToolsFromApp func", func() {
1111
var (
1212
appStr string
1313
globalVars map[string]any
@@ -25,7 +25,7 @@ var _ = Describe("getAppTools func", func() {
2525
}
2626
})
2727
It("should return err", func() {
28-
_, err := getAppTools(appStr, globalVars, templateMap)
28+
_, err := getToolsFromApp(appStr, globalVars, templateMap)
2929
Expect(err).Error().Should(HaveOccurred())
3030
Expect(err.Error()).Should(ContainSubstring("app render globalVars failed"))
3131
})
@@ -35,7 +35,7 @@ var _ = Describe("getAppTools func", func() {
3535
appStr = "fsdfsd{123213}"
3636
})
3737
It("should return error", func() {
38-
_, err := getAppTools(appStr, globalVars, templateMap)
38+
_, err := getToolsFromApp(appStr, globalVars, templateMap)
3939
Expect(err).Error().Should(HaveOccurred())
4040
Expect(err.Error()).Should(ContainSubstring("app parse yaml failed"))
4141
})
@@ -51,7 +51,7 @@ ci:
5151
templateName:`
5252
})
5353
It("should return error", func() {
54-
_, err := getAppTools(appStr, globalVars, templateMap)
54+
_, err := getToolsFromApp(appStr, globalVars, templateMap)
5555
Expect(err).Error().Should(HaveOccurred())
5656
Expect(err.Error()).Should(ContainSubstring("app[test] get pipeline tools failed"))
5757
})
@@ -65,7 +65,7 @@ cd:
6565
templateName:`
6666
})
6767
It("should return error", func() {
68-
_, err := getAppTools(appStr, globalVars, templateMap)
68+
_, err := getToolsFromApp(appStr, globalVars, templateMap)
6969
Expect(err).Error().Should(HaveOccurred())
7070
Expect(err.Error()).Should(ContainSubstring("app.repo field can't be empty"))
7171
})
@@ -81,7 +81,7 @@ cd:
8181
templateName:`
8282
})
8383
It("should return error", func() {
84-
_, err := getAppTools(appStr, globalVars, templateMap)
84+
_, err := getToolsFromApp(appStr, globalVars, templateMap)
8585
Expect(err).Error().Should(HaveOccurred())
8686
Expect(err.Error()).Should(ContainSubstring("app[test] get pipeline tools failed"))
8787
})
@@ -184,7 +184,7 @@ options:
184184
"instanceID": "service-A",
185185
},
186186
}
187-
tools, err := getAppTools(appStr, globalVars, templateMap)
187+
tools, err := getToolsFromApp(appStr, globalVars, templateMap)
188188
Expect(err).Error().ShouldNot(HaveOccurred())
189189
Expect(tools).ShouldNot(BeNil())
190190
Expect(len(tools)).Should(Equal(3))
@@ -222,7 +222,7 @@ var _ = Describe("appRaw struct", func() {
222222
})
223223
})
224224
})
225-
Context("getPipelineTools method", func() {
225+
Context("generateCICDToolsFromAppConfig method", func() {
226226
When("config is not valid", func() {
227227
BeforeEach(func() {
228228
rawConfig = []pipelineRaw{
@@ -234,7 +234,7 @@ var _ = Describe("appRaw struct", func() {
234234
a.CIRawConfigs = rawConfig
235235
})
236236
It("should return error", func() {
237-
_, err := a.getPipelineTools(templateMap, globalVars)
237+
_, err := a.generateCICDToolsFromAppConfig(templateMap, globalVars)
238238
Expect(err).Error().Should(HaveOccurred())
239239
Expect(err.Error()).Should(ContainSubstring(".templateName is required"))
240240
})
@@ -252,7 +252,7 @@ var _ = Describe("appRaw struct", func() {
252252
a.CIRawConfigs = rawConfig
253253
})
254254
It("should return pipeline array", func() {
255-
p, err := a.getPipelineTools(templateMap, globalVars)
255+
p, err := a.generateCICDToolsFromAppConfig(templateMap, globalVars)
256256
Expect(err).Error().ShouldNot(HaveOccurred())
257257
Expect(len(p)).Should(Equal(2))
258258
Expect(p[0].Name).Should(Equal("github-actions"))

internal/pkg/configmanager/config.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type (
2727
Tools Tools `yaml:"tools"`
2828
State *State
2929
}
30-
// ConfigRaw is used to describe original raw configs read from files
31-
ConfigRaw struct {
30+
// RawConfig is used to describe original raw configs read from files
31+
RawConfig struct {
3232
VarFile configFileLoc `yaml:"varFile" mapstructure:"varFile"`
3333
ToolFile configFileLoc `yaml:"toolFile" mapstructure:"toolFile"`
3434
AppFile configFileLoc `yaml:"appFile" mapstructure:"appFile"`
@@ -70,8 +70,8 @@ func (c *Config) validate() error {
7070
return nil
7171
}
7272

73-
// newConfigRaw generate new ConfigRaw options
74-
func newConfigRaw(configFileLocation string) (*ConfigRaw, error) {
73+
// newRawConfig generate new RawConfig options
74+
func newRawConfig(configFileLocation string) (*RawConfig, error) {
7575
// 1. get baseDir from configFile
7676
baseDir, err := file.GetFileAbsDirPath(configFileLocation)
7777
if err != nil {
@@ -87,15 +87,15 @@ func newConfigRaw(configFileLocation string) (*ConfigRaw, error) {
8787
// otherwise yaml.Unmarshal can only read the content before the first "---"
8888
configBytes = bytes.Replace(configBytes, []byte("---"), []byte("\n"), -1)
8989

90-
// 3. decode total yaml files to get ConfigRaw
91-
var configRaw ConfigRaw
92-
if err := yaml.Unmarshal(configBytes, &configRaw); err != nil && !errors.Is(err, io.EOF) {
90+
// 3. decode total yaml files to get RawConfig
91+
var RawConfig RawConfig
92+
if err := yaml.Unmarshal(configBytes, &RawConfig); err != nil && !errors.Is(err, io.EOF) {
9393
log.Errorf("Please verify the format of your config. Error: %s.", err)
9494
return nil, err
9595
}
96-
configRaw.configFileBaseDir = baseDir
97-
configRaw.globalBytes = configBytes
98-
return &configRaw, nil
96+
RawConfig.configFileBaseDir = baseDir
97+
RawConfig.globalBytes = configBytes
98+
return &RawConfig, nil
9999
}
100100

101101
// loadConfigFile get config file content by location
@@ -112,7 +112,7 @@ func loadConfigFile(fileLoc string) ([]byte, error) {
112112
}
113113

114114
// getGlobalVars will get global variables from GlobalVars field and varFile content
115-
func (r *ConfigRaw) getGlobalVars() (map[string]any, error) {
115+
func (r *RawConfig) getGlobalVars() (map[string]any, error) {
116116
valueContent, err := r.VarFile.getContentBytes(r.configFileBaseDir)
117117
if err != nil {
118118
return nil, err
@@ -127,9 +127,9 @@ func (r *ConfigRaw) getGlobalVars() (map[string]any, error) {
127127
return globalVars, nil
128128
}
129129

130-
// UnmarshalYAML is used for ConfigRaw
130+
// UnmarshalYAML is used for RawConfig
131131
// it will put variables fields in globalVars field
132-
func (r *ConfigRaw) UnmarshalYAML(value *yaml.Node) error {
132+
func (r *RawConfig) UnmarshalYAML(value *yaml.Node) error {
133133
configMap := make(map[string]any)
134134
if err := value.Decode(configMap); err != nil {
135135
return err
@@ -138,7 +138,7 @@ func (r *ConfigRaw) UnmarshalYAML(value *yaml.Node) error {
138138
}
139139

140140
// getApps will get Apps from appStr config
141-
func (r *ConfigRaw) getAppsTools(globalVars map[string]any) (Tools, error) {
141+
func (r *RawConfig) getAppsTools(globalVars map[string]any) (Tools, error) {
142142
// 1. get tools config str
143143
yamlPath := "$.apps[*]"
144144
fileBytes, err := r.AppFile.getContentBytes(r.configFileBaseDir)
@@ -158,7 +158,7 @@ func (r *ConfigRaw) getAppsTools(globalVars map[string]any) (Tools, error) {
158158
// 3. render app with pipelineTemplate and globalVars
159159
var tools Tools
160160
for _, appConfigStr := range appArray {
161-
appTools, err := getAppTools(appConfigStr, globalVars, templateMap)
161+
appTools, err := getToolsFromApp(appConfigStr, globalVars, templateMap)
162162
if err != nil {
163163
return nil, err
164164
}
@@ -168,7 +168,7 @@ func (r *ConfigRaw) getAppsTools(globalVars map[string]any) (Tools, error) {
168168
}
169169

170170
// getTools get Tools from tool config
171-
func (r *ConfigRaw) getTools(globalVars map[string]any) (Tools, error) {
171+
func (r *RawConfig) getTools(globalVars map[string]any) (Tools, error) {
172172
// 1. get tools config str
173173
yamlPath := "$.tools[*]"
174174
fileBytes, err := r.ToolFile.getContentBytes(r.configFileBaseDir)
@@ -197,7 +197,7 @@ func (r *ConfigRaw) getTools(globalVars map[string]any) (Tools, error) {
197197
}
198198

199199
// getPipelineTemplatesMap generate template name/rawString map
200-
func (r *ConfigRaw) getPipelineTemplatesMap() (map[string]string, error) {
200+
func (r *RawConfig) getPipelineTemplatesMap() (map[string]string, error) {
201201
yamlPath := "$.pipelineTemplates[*]"
202202
fileBytes, err := r.TemplateFile.getContentBytes(r.configFileBaseDir)
203203
if err != nil {
@@ -225,7 +225,7 @@ func (f configFileLoc) getContentBytes(baseDir string) ([]byte, error) {
225225
return []byte{}, nil
226226
}
227227
// refer other config file path by directory of main config file
228-
fileAbs, err := file.GenAbsFilePath(baseDir, string(f))
228+
fileAbs, err := file.GenerateAbsFilePath(baseDir, string(f))
229229
if err != nil {
230230
return nil, err
231231
}

internal/pkg/configmanager/config_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _ = Describe("Config struct", func() {
2222
})
2323
})
2424

25-
var _ = Describe("newConfigRaw func", func() {
25+
var _ = Describe("newRawConfig func", func() {
2626
var (
2727
fLoc string
2828
baseDir string
@@ -38,7 +38,7 @@ var _ = Describe("newConfigRaw func", func() {
3838
fLoc = "not_exist"
3939
})
4040
It("should return err", func() {
41-
_, err := newConfigRaw(fLoc)
41+
_, err := newRawConfig(fLoc)
4242
Expect(err).Error().Should(HaveOccurred())
4343
Expect(err.Error()).Should(ContainSubstring("no such file or directory"))
4444
})
@@ -49,22 +49,22 @@ var _ = Describe("newConfigRaw func", func() {
4949
Expect(err).Error().ShouldNot(HaveOccurred())
5050
})
5151
It("should return err", func() {
52-
_, err := newConfigRaw(fLoc)
52+
_, err := newRawConfig(fLoc)
5353
Expect(err).Error().Should(HaveOccurred())
5454
Expect(err.Error()).Should(ContainSubstring("cannot unmarshal"))
5555
})
5656
})
5757
})
5858

59-
var _ = Describe("ConfigRaw struct", func() {
59+
var _ = Describe("RawConfig struct", func() {
6060
var (
61-
r *ConfigRaw
61+
r *RawConfig
6262
baseDir string
6363
fLoc string
6464
globalVars map[string]any
6565
)
6666
BeforeEach(func() {
67-
r = &ConfigRaw{}
67+
r = &RawConfig{}
6868
baseDir = GinkgoT().TempDir()
6969
f, err := os.CreateTemp(baseDir, "test")
7070
Expect(err).Error().ShouldNot(HaveOccurred())

internal/pkg/configmanager/manager.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ func NewManager(configFileName string) *Manager {
1313
// LoadConfig reads an input file as a general config.
1414
// It will return "non-nil, err" or "nil, err".
1515
func (m *Manager) LoadConfig() (*Config, error) {
16-
// 1. get new ConfigRaw from ConfigFile
17-
configRaw, err := newConfigRaw(m.ConfigFile)
16+
// 1. get new RawConfig from ConfigFile
17+
RawConfig, err := newRawConfig(m.ConfigFile)
1818
if err != nil {
1919
return nil, err
2020
}
2121
// 2. get all globals vars
22-
globalVars, err := configRaw.getGlobalVars()
22+
globalVars, err := RawConfig.getGlobalVars()
2323
if err != nil {
2424
return nil, err
2525
}
26-
// 3. get Apps from ConfigRaw
27-
appTools, err := configRaw.getAppsTools(globalVars)
26+
// 3. get Apps from RawConfig
27+
appTools, err := RawConfig.getAppsTools(globalVars)
2828
if err != nil {
2929
return nil, err
3030
}
3131

32-
// 4. get Tools from ConfigRaw
33-
tools, err := configRaw.getTools(globalVars)
32+
// 4. get Tools from RawConfig
33+
tools, err := RawConfig.getTools(globalVars)
3434
if err != nil {
3535
return nil, err
3636
}
3737
tools = append(tools, appTools...)
3838
config := &Config{
39-
PluginDir: configRaw.PluginDir,
40-
State: configRaw.State,
39+
PluginDir: RawConfig.PluginDir,
40+
State: RawConfig.State,
4141
Tools: tools,
4242
}
4343
//5. validate config is valid

internal/pkg/configmanager/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ tools:
424424
})
425425

426426
Context("LoadConfig method", func() {
427-
When("get configRaw failed", func() {
427+
When("get RawConfig failed", func() {
428428
BeforeEach(func() {
429429
m.ConfigFile = "not_exist"
430430
})

internal/pkg/configmanager/pipelineTemplate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (p *pipelineRaw) newPipelineFromTemplate(templateMap map[string]string, glo
9090
return nil, fmt.Errorf("%s not found in pipelineTemplates", p.TemplateName)
9191
}
9292

93-
allVars := mapz.MergeMaps(globalVars, p.Vars)
93+
allVars := mapz.Merge(globalVars, p.Vars)
9494
templateRenderdStr, err := renderConfigWithVariables(templateStr, allVars)
9595
if err != nil {
9696
return nil, fmt.Errorf("%s render pipelineTemplate failed: %+w", p.TemplateName, err)

pkg/util/file/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func CopyFile(srcFile, dstFile string) (err error) {
4545
return dFile.Sync()
4646
}
4747

48-
// GenAbsFilePath return all the path with a given file name
49-
func GenAbsFilePath(baseDir, file string) (string, error) {
48+
// GenerateAbsFilePath return all the path with a given file name
49+
func GenerateAbsFilePath(baseDir, file string) (string, error) {
5050
file = filepath.Join(baseDir, file)
5151

5252
fileExist := func(path string) bool {

pkg/util/file/file_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ var _ = Describe("CopyFile func", func() {
4040
})
4141
})
4242

43-
var _ = Describe("GenAbsFilePath func", func() {
43+
var _ = Describe("GenerateAbsFilePath func", func() {
4444
var baseDir, fileName string
4545
When("file not exist", func() {
4646
BeforeEach(func() {
4747
baseDir = "not_exist"
4848
fileName = "not_exist"
4949
})
5050
It("should return err", func() {
51-
_, err := file.GenAbsFilePath(baseDir, fileName)
51+
_, err := file.GenerateAbsFilePath(baseDir, fileName)
5252
Expect(err).Error().Should(HaveOccurred())
5353
})
5454
})
@@ -60,7 +60,7 @@ var _ = Describe("GenAbsFilePath func", func() {
6060
fileName = filepath.Base(testFile.Name())
6161
})
6262
It("should return absPath", func() {
63-
path, err := file.GenAbsFilePath(baseDir, fileName)
63+
path, err := file.GenerateAbsFilePath(baseDir, fileName)
6464
Expect(err).Error().ShouldNot(HaveOccurred())
6565
Expect(path).Should(Equal(filepath.Join(baseDir, fileName)))
6666
})

0 commit comments

Comments
 (0)