Skip to content

Commit 92902d7

Browse files
committed
Fix last code smells
1 parent 2eb1f34 commit 92902d7

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

otlpinf/otlpinf_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
POLICIES_API = "/api/v1/policies"
2020
HTTP_YAML_CONTENT = "application/x-yaml"
2121
ERROR_MSG = "HTTP status code = %v, wanted %v"
22+
NEW_ERR_MSG = "New() error = %v"
2223
POST_ERR_MSG = "http.Post() error = %v"
2324
YAML_ERR_MSG = "yaml.NewEncoder() error = %v"
2425
)
@@ -34,7 +35,7 @@ func TestOtlpInfRestApis(t *testing.T) {
3435

3536
otlp, err := New(logger, &cfg)
3637
if err != nil {
37-
t.Errorf("New() error = %v", err)
38+
t.Errorf(NEW_ERR_MSG, err)
3839
}
3940

4041
otlp.setupRouter()
@@ -125,7 +126,7 @@ func TestOtlpinfCreateDeletePolicy(t *testing.T) {
125126
// Act and Assert
126127
otlp, err := New(logger, &cfg)
127128
if err != nil {
128-
t.Errorf("New() error = %v", err)
129+
t.Errorf(NEW_ERR_MSG, err)
129130
}
130131

131132
ctx, cancel := context.WithCancel(context.Background())
@@ -253,7 +254,7 @@ func TestOtlpinfCreateInvalidPolicy(t *testing.T) {
253254
// Act and Assert
254255
otlp, err := New(logger, &cfg)
255256
if err != nil {
256-
t.Errorf("New() error = %v", err)
257+
t.Errorf(NEW_ERR_MSG, err)
257258
}
258259

259260
ctx, cancel := context.WithCancel(context.Background())

runner/runner.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Runner struct {
5454
policyFile string
5555
featureGates string
5656
sets []string
57+
options []string
5758
selfTelemetry bool
5859
state State
5960
cancelFunc context.CancelFunc
@@ -108,37 +109,37 @@ func (r *Runner) Configure(c *config.Policy) error {
108109
}
109110
}
110111

111-
return nil
112-
}
113-
114-
func (r *Runner) Start(ctx context.Context, cancelFunc context.CancelFunc) error {
115-
r.cancelFunc = cancelFunc
116-
r.ctx = ctx
117-
118-
sOptions := []string{
112+
r.options = []string{
119113
"--config",
120114
r.policyFile,
121115
}
122116

123117
if !r.selfTelemetry {
124-
sOptions = append(sOptions, "--set=service.telemetry.metrics.level=None")
118+
r.options = append(r.options, "--set=service.telemetry.metrics.level=None")
125119
}
126120

127121
if len(r.featureGates) > 0 {
128-
sOptions = append(sOptions, "--feature-gates", r.featureGates)
122+
r.options = append(r.options, "--feature-gates", r.featureGates)
129123
}
130124

131125
if len(r.sets) > 0 {
132-
sOptions = append(sOptions, r.sets...)
126+
r.options = append(r.options, r.sets...)
133127
}
134128

129+
return nil
130+
}
131+
132+
func (r *Runner) Start(ctx context.Context, cancelFunc context.CancelFunc) error {
133+
r.cancelFunc = cancelFunc
134+
r.ctx = ctx
135+
135136
exe, err := memexec.New(otel_contrib)
136137
if err != nil {
137138
return err
138139
}
139140
defer exe.Close()
140141

141-
r.cmd = exe.CommandContext(ctx, sOptions...)
142+
r.cmd = exe.CommandContext(ctx, r.options...)
142143
if r.cmd.Err != nil {
143144
return r.cmd.Err
144145
}

0 commit comments

Comments
 (0)