Skip to content

Commit 95ff29c

Browse files
authored
test: Fix golden gen for long wd paths (#6021)
1 parent dffd795 commit 95ff29c

File tree

57 files changed

+72
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+72
-63
lines changed

cli/root_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ var updateGoldenFiles = flag.Bool("update", false, "update .golden files")
3131
//nolint:tparallel,paralleltest // These test sets env vars.
3232
func TestCommandHelp(t *testing.T) {
3333
commonEnv := map[string]string{
34-
"CODER_CONFIG_DIR": "/tmp/coder-cli-test-config",
34+
"HOME": "~",
35+
"CODER_CONFIG_DIR": "~/.config/coderv2",
3536
}
3637

3738
type testCase struct {
@@ -48,7 +49,7 @@ func TestCommandHelp(t *testing.T) {
4849
name: "coder server --help",
4950
cmd: []string{"server", "--help"},
5051
env: map[string]string{
51-
"CODER_CACHE_DIRECTORY": "/tmp/coder-cli-test-cache",
52+
"CODER_CACHE_DIRECTORY": "~/.cache/coder",
5253
},
5354
},
5455
{
@@ -104,19 +105,27 @@ ExtractCommandPathsLoop:
104105

105106
ctx, _ := testutil.Context(t)
106107

108+
tmpwd := "/"
109+
if runtime.GOOS == "windows" {
110+
tmpwd = "C:\\"
111+
}
112+
err := os.Chdir(tmpwd)
107113
var buf bytes.Buffer
108114
root, _ := clitest.New(t, tt.cmd...)
109115
root.SetOut(&buf)
110-
err := root.ExecuteContext(ctx)
116+
assert.NoError(t, err)
117+
err = root.ExecuteContext(ctx)
118+
err2 := os.Chdir(wd)
111119
require.NoError(t, err)
120+
require.NoError(t, err2)
112121

113122
got := buf.Bytes()
114123
// Remove CRLF newlines (Windows).
115124
got = bytes.ReplaceAll(got, []byte{'\r', '\n'}, []byte{'\n'})
116125

117126
// The `coder templates create --help` command prints the path
118127
// to the working directory (--directory flag default value).
119-
got = bytes.ReplaceAll(got, []byte(wd), []byte("/tmp/coder-cli-test-workdir"))
128+
got = bytes.ReplaceAll(got, []byte(fmt.Sprintf("%q", tmpwd)), []byte("\"[current directory]\""))
120129

121130
gf := filepath.Join("testdata", strings.Replace(tt.name, " ", "_", -1)+".golden")
122131
if *updateGoldenFiles {

cli/testdata/coder_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Workspace Commands:
4848

4949
Flags:
5050
--global-config coder Path to the global coder config directory.
51-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
51+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
5252
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
5353
Consumes $CODER_HEADER
5454
-h, --help help for coder

cli/testdata/coder_agent_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Flags:
1313

1414
Global Flags:
1515
--global-config coder Path to the global coder config directory.
16-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
16+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
1717
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
1818
Consumes $CODER_HEADER
1919
--no-feature-warning Suppress warnings about unlicensed features.

cli/testdata/coder_config-ssh_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Flags:
2727

2828
Global Flags:
2929
--global-config coder Path to the global coder config directory.
30-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
30+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
3131
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
3232
Consumes $CODER_HEADER
3333
--no-feature-warning Suppress warnings about unlicensed features.

cli/testdata/coder_create_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Flags:
2323

2424
Global Flags:
2525
--global-config coder Path to the global coder config directory.
26-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
26+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
2727
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
2828
Consumes $CODER_HEADER
2929
--no-feature-warning Suppress warnings about unlicensed features.

cli/testdata/coder_delete_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Flags:
1414

1515
Global Flags:
1616
--global-config coder Path to the global coder config directory.
17-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
17+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
1818
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
1919
Consumes $CODER_HEADER
2020
--no-feature-warning Suppress warnings about unlicensed features.

cli/testdata/coder_dotfiles_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Flags:
1717

1818
Global Flags:
1919
--global-config coder Path to the global coder config directory.
20-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
20+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
2121
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
2222
Consumes $CODER_HEADER
2323
--no-feature-warning Suppress warnings about unlicensed features.

cli/testdata/coder_list_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Flags:
1616

1717
Global Flags:
1818
--global-config coder Path to the global coder config directory.
19-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
19+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
2020
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
2121
Consumes $CODER_HEADER
2222
--no-feature-warning Suppress warnings about unlicensed features.

cli/testdata/coder_login_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Flags:
2020

2121
Global Flags:
2222
--global-config coder Path to the global coder config directory.
23-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
23+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
2424
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
2525
Consumes $CODER_HEADER
2626
--no-feature-warning Suppress warnings about unlicensed features.

cli/testdata/coder_logout_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Flags:
99

1010
Global Flags:
1111
--global-config coder Path to the global coder config directory.
12-
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
12+
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
1313
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
1414
Consumes $CODER_HEADER
1515
--no-feature-warning Suppress warnings about unlicensed features.

0 commit comments

Comments
 (0)