Skip to content

Commit 7bf6d85

Browse files
committed
fix: issue --namespace showing twice
1 parent d8b8a6e commit 7bf6d85

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

docs/Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ GEM
231231
rb-inotify (0.10.1)
232232
ffi (~> 1.0)
233233
ref (2.0.0)
234-
rexml (3.3.6)
234+
rexml (3.3.3)
235235
strscan
236236
rouge (3.26.0)
237237
rubyzip (2.3.0)

modules/helm/cmd_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package helm
2+
3+
import (
4+
"testing"
5+
6+
"github.com/gruntwork-io/terratest/modules/k8s"
7+
"github.com/gruntwork-io/terratest/modules/logger"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestPrepareHelmCommand(t *testing.T) {
12+
t.Parallel()
13+
14+
options := &Options{
15+
KubectlOptions: &k8s.KubectlOptions{
16+
Namespace: "test-namespace",
17+
},
18+
EnvVars: map[string]string{"SampleEnv": "test_value"},
19+
Logger: logger.Default,
20+
}
21+
t.Run("command without additional args", func(t *testing.T) {
22+
cmd := prepareHelmCommand(t, options, "install")
23+
assert.Equal(t, "helm", cmd.Command)
24+
assert.Contains(t, cmd.Args, "install")
25+
assert.Contains(t, cmd.Args, "--namespace")
26+
assert.Contains(t, cmd.Args, "test-namespace")
27+
assert.Equal(t, ".", cmd.WorkingDir)
28+
assert.Equal(t, options.EnvVars, cmd.Env)
29+
assert.Equal(t, options.Logger, cmd.Logger)
30+
})
31+
t.Run("Command with additional args", func(t *testing.T) {
32+
cmd := prepareHelmCommand(t, options, "upgrade", "--install", "my-release", "my-chart")
33+
assert.Equal(t, "helm", cmd.Command)
34+
assert.Contains(t, cmd.Args, "upgrade")
35+
assert.Contains(t, cmd.Args, "--install")
36+
assert.Contains(t, cmd.Args, "my-release")
37+
assert.Contains(t, cmd.Args, "my-chart")
38+
assert.Contains(t, cmd.Args, "--namespace")
39+
assert.Contains(t, cmd.Args, "test-namespace")
40+
})
41+
42+
t.Run("Command with namespace in additional args", func(t *testing.T) {
43+
cmd := prepareHelmCommand(t, options, "install", "--namespace", "custom-namespace")
44+
assert.Equal(t, "helm", cmd.Command)
45+
assert.Contains(t, cmd.Args, "install")
46+
assert.Contains(t, cmd.Args, "--namespace")
47+
assert.Contains(t, cmd.Args, "custom-namespace")
48+
assert.NotContains(t, cmd.Args, "test-namespace")
49+
})
50+
}

modules/terraform/output.go

-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"reflect"
88
"strconv"
9-
"strings"
109

1110
"github.com/gruntwork-io/terratest/modules/testing"
1211
"github.com/stretchr/testify/require"
@@ -301,35 +300,17 @@ func OutputStructE(t testing.TestingT, options *Options, key string, v interface
301300
if err != nil {
302301
return err
303302
}
304-
out = cleanOutput(out)
305303

306304
return json.Unmarshal([]byte(out), &v)
307305
}
308306

309-
// cleanOutput removes lines containing "INFO" and non-printable ASCII characters from the output.
310-
func cleanOutput(out string) string {
311-
var result []rune
312-
for _, line := range strings.Split(out, "\n") {
313-
if strings.Contains(line, "INFO") {
314-
continue
315-
}
316-
for _, r := range line {
317-
if r >= 32 && r < 127 { // Keep printable ASCII characters only
318-
result = append(result, r)
319-
}
320-
}
321-
}
322-
return string(result)
323-
}
324-
325307
// OutputForKeysE calls terraform output for the given key list and returns values as a map.
326308
// The returned values are of type interface{} and need to be type casted as necessary. Refer to output_test.go
327309
func OutputForKeysE(t testing.TestingT, options *Options, keys []string) (map[string]interface{}, error) {
328310
out, err := OutputJsonE(t, options, "")
329311
if err != nil {
330312
return nil, err
331313
}
332-
out = cleanOutput(out)
333314

334315
outputMap := map[string]map[string]interface{}{}
335316
if err := json.Unmarshal([]byte(out), &outputMap); err != nil {

0 commit comments

Comments
 (0)