Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cli/wizard/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"bytes"
"encoding/hex"
"os"
"path/filepath"
"testing"

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

func TestSetConfigValueForTestUsesTemporaryRoot(t *testing.T) {
ctx := &WizardContext{}
setConfigValueForTest(t, ctx, "keyring.namespace", "test")

if _, err := os.Stat(filepath.Join(ctx.RootDir, "config.yaml")); err != nil {
t.Fatalf("expected config in temporary root: %v", err)
}
}
Comment on lines +54 to +61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: you cover with tests and internal helper function for tests. This looks unconventional. I'd remove it


// setupWorkingDirectoryForTest is a helper that temporarily changes the working directory to a
// temporary one for use by the test. Current working directory will be restored after the test.
// It will return the temporary directory that was created.
Expand Down
Loading