Skip to content

test: Fix golden gen for long wd paths #6021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
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
17 changes: 13 additions & 4 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var updateGoldenFiles = flag.Bool("update", false, "update .golden files")
//nolint:tparallel,paralleltest // These test sets env vars.
func TestCommandHelp(t *testing.T) {
commonEnv := map[string]string{
"CODER_CONFIG_DIR": "/tmp/coder-cli-test-config",
"HOME": "~",
"CODER_CONFIG_DIR": "~/.config/coderv2",
}

type testCase struct {
Expand All @@ -48,7 +49,7 @@ func TestCommandHelp(t *testing.T) {
name: "coder server --help",
cmd: []string{"server", "--help"},
env: map[string]string{
"CODER_CACHE_DIRECTORY": "/tmp/coder-cli-test-cache",
"CODER_CACHE_DIRECTORY": "~/.cache/coder",
},
},
{
Expand Down Expand Up @@ -104,19 +105,27 @@ ExtractCommandPathsLoop:

ctx, _ := testutil.Context(t)

tmpwd := "/"
if runtime.GOOS == "windows" {
tmpwd = "C:\\"
}
err := os.Chdir(tmpwd)
var buf bytes.Buffer
root, _ := clitest.New(t, tt.cmd...)
root.SetOut(&buf)
err := root.ExecuteContext(ctx)
assert.NoError(t, err)
err = root.ExecuteContext(ctx)
err2 := os.Chdir(wd)
require.NoError(t, err)
require.NoError(t, err2)

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

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

gf := filepath.Join("testdata", strings.Replace(tt.name, " ", "_", -1)+".golden")
if *updateGoldenFiles {
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Workspace Commands:

Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
-h, --help help for coder
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_agent_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_config-ssh_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_create_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_delete_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_dotfiles_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_list_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_login_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_logout_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_port-forward_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_publickey_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_rename_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_reset-password_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_restart_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_scaletest_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_scaletest_cleanup_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_schedule_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_schedule_override-stop_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_schedule_show_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_schedule_start_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_schedule_stop_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
4 changes: 2 additions & 2 deletions cli/testdata/coder_server_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Flags:
set, it will be used for compatibility
with systemd.
Consumes $CODER_CACHE_DIRECTORY (default
"/tmp/coder-cli-test-cache")
"~/.cache/coder")
--dangerous-allow-path-app-sharing Allow workspace apps that are not served
from subdomains to be shared. Path-based
app sharing is DISABLED by default for
Expand Down Expand Up @@ -307,7 +307,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_show_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_speedtest_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_ssh_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_start_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_state_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_state_pull_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_state_push_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_stop_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flags:

Global Flags:
--global-config coder Path to the global coder config directory.
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
Consumes $CODER_CONFIG_DIR (default "~/.config/coderv2")
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
Consumes $CODER_HEADER
--no-feature-warning Suppress warnings about unlicensed features.
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_templates_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Flags:

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