Skip to content

Commit 372c153

Browse files
committed
refactor: receiver of renderInstanceIDtoOptions
Signed-off-by: Bird <[email protected]>
1 parent e831f25 commit 372c153

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
lines changed

internal/pkg/configmanager/config.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ type Config struct {
1111
Tools Tools `yaml:"tools"`
1212
}
1313

14-
func (c *Config) renderInstanceIDtoOptions() {
15-
for _, t := range c.Tools {
16-
if t.Options == nil {
17-
t.Options = make(RawOptions)
18-
}
19-
t.Options["instanceID"] = t.InstanceID
20-
}
21-
}
22-
2314
func (c *Config) validate() error {
2415
if c.Config.State == nil {
2516
return fmt.Errorf("config.state is not defined")

internal/pkg/configmanager/config_test.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,10 @@ import (
66
)
77

88
var _ = Describe("Config struct", func() {
9-
var (
10-
c *Config
11-
toolName, instanceID string
12-
)
9+
var c *Config
10+
1311
BeforeEach(func() {
1412
c = &Config{}
15-
toolName = "test_tool"
16-
instanceID = "test_instance"
17-
})
18-
Context("renderInstanceIDtoOptions method", func() {
19-
When("tool option is null", func() {
20-
BeforeEach(func() {
21-
c.Tools = Tools{
22-
{Name: toolName, InstanceID: instanceID},
23-
}
24-
})
25-
It("should set nil to RawOptions", func() {
26-
c.renderInstanceIDtoOptions()
27-
Expect(len(c.Tools)).Should(Equal(1))
28-
tool := c.Tools[0]
29-
Expect(tool.Options).Should(Equal(RawOptions{
30-
"instanceID": instanceID,
31-
}))
32-
})
33-
})
3413
})
3514
Context("validate method", func() {
3615
When("config state is null", func() {

internal/pkg/configmanager/configmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (m *Manager) LoadConfig() (*Config, error) {
2929
return nil, err
3030
}
3131
// set instanceID in options
32-
c.renderInstanceIDtoOptions()
32+
c.Tools.renderInstanceIDtoOptions()
3333

3434
// step 2: check config is valid
3535
if err = c.validate(); err != nil {

internal/pkg/configmanager/tool.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,12 @@ func (tools Tools) updateToolDepends(dependTools Tools) {
157157
}
158158
}
159159
}
160+
161+
func (tools Tools) renderInstanceIDtoOptions() {
162+
for _, t := range tools {
163+
if t.Options == nil {
164+
t.Options = make(RawOptions)
165+
}
166+
t.Options["instanceID"] = t.InstanceID
167+
}
168+
}

internal/pkg/configmanager/tool_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,29 @@ var _ = Describe("Tool struct", func() {
139139
})
140140
})
141141
})
142+
143+
var _ = Describe("Tool struct", func() {
144+
var tools Tools
145+
146+
const (
147+
toolName = "test_tool"
148+
instanceID = "test_instance"
149+
)
150+
Context("renderInstanceIDtoOptions method", func() {
151+
BeforeEach(func() {
152+
tools = Tools{
153+
{Name: toolName, InstanceID: instanceID},
154+
}
155+
})
156+
When("tool option is null", func() {
157+
It("should set nil to RawOptions", func() {
158+
tools.renderInstanceIDtoOptions()
159+
Expect(len(tools)).Should(Equal(1))
160+
tool := tools[0]
161+
Expect(tool.Options).Should(Equal(RawOptions{
162+
"instanceID": instanceID,
163+
}))
164+
})
165+
})
166+
})
167+
})

0 commit comments

Comments
 (0)