Skip to content

Commit

Permalink
address PR comments by zmb
Browse files Browse the repository at this point in the history
  • Loading branch information
strideynet committed May 10, 2022
1 parent 6e71633 commit 93a4214
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
4 changes: 3 additions & 1 deletion lib/utils/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ package golden
import (
"os"
"path/filepath"
"strconv"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -89,7 +90,8 @@ func pathForFile(t *testing.T, name string) string {
// data.
func ShouldSet() bool {
env := os.Getenv("GOLDEN_UPDATE")
return env == "y" || env == "1"
should, _ := strconv.ParseBool(env)
return should
}

// SetNamed writes the supplied data to a named golden file for the current
Expand Down
18 changes: 6 additions & 12 deletions tool/tbot/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"

"github.com/gravitational/teleport/lib/utils/golden"
Expand All @@ -35,14 +34,14 @@ func TestRun_Configure(t *testing.T) {
// If we switch to a more dependency injected model for botfs, we can
// ensure that the test one returns the same value across operating systems.
normalizeOSDependentValues := func(data []byte) []byte {
str := string(data)
str = strings.ReplaceAll(
str, "symlinks: try-secure", "symlinks: secure",
cpy := append([]byte{}, data...)
cpy = bytes.ReplaceAll(
cpy, []byte("symlinks: try-secure"), []byte("symlinks: secure"),
)
str = strings.ReplaceAll(
str, `acls: "off"`, "acls: try",
cpy = bytes.ReplaceAll(
cpy, []byte(`acls: "off"`), []byte("acls: try"),
)
return []byte(str)
return cpy
}

baseArgs := []string{"configure"}
Expand Down Expand Up @@ -72,10 +71,7 @@ func TestRun_Configure(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
t.Run("file", func(t *testing.T) {
t.Parallel()

path := filepath.Join(t.TempDir(), "config.yaml")
args := append(tt.args, []string{"-o", path}...)
err := Run(args, nil)
Expand All @@ -91,8 +87,6 @@ func TestRun_Configure(t *testing.T) {
})

t.Run("stdout", func(t *testing.T) {
t.Parallel()

stdout := new(bytes.Buffer)
err := Run(tt.args, stdout)
require.NoError(t, err)
Expand Down

0 comments on commit 93a4214

Please sign in to comment.