Skip to content

Commit ac84cbd

Browse files
committed
test: isolate wizard config files
1 parent c732d45 commit ac84cbd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

cli/wizard/utils_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"bytes"
1515
"encoding/hex"
1616
"os"
17+
"path/filepath"
1718
"testing"
1819

1920
"github.com/sourcenetwork/defradb/keyring"
@@ -37,6 +38,9 @@ func unsetEnvForTest(t *testing.T, key string) {
3738
// setConfigValueForTest is a helper that unsets a value from the wizard's config.yaml file,
3839
// but which will restore the original value after the test.
3940
func setConfigValueForTest(t *testing.T, ctx *WizardContext, key string, value any) {
41+
if ctx.RootDir == "" {
42+
ctx.RootDir = t.TempDir()
43+
}
4044
originalValue, ok := getConfigValue(ctx, key).(string)
4145
if !ok {
4246
t.Fatal("failed to get original value")
@@ -47,6 +51,15 @@ func setConfigValueForTest(t *testing.T, ctx *WizardContext, key string, value a
4751
_ = setConfigValue(ctx, key, value)
4852
}
4953

54+
func TestSetConfigValueForTestUsesTemporaryRoot(t *testing.T) {
55+
ctx := &WizardContext{}
56+
setConfigValueForTest(t, ctx, "keyring.namespace", "test")
57+
58+
if _, err := os.Stat(filepath.Join(ctx.RootDir, "config.yaml")); err != nil {
59+
t.Fatalf("expected config in temporary root: %v", err)
60+
}
61+
}
62+
5063
// setupWorkingDirectoryForTest is a helper that temporarily changes the working directory to a
5164
// temporary one for use by the test. Current working directory will be restored after the test.
5265
// It will return the temporary directory that was created.

0 commit comments

Comments
 (0)