Skip to content

feat: add YAML support to server #6934

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 42 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0d08b84
big wip
ammario Mar 30, 2023
fce8e5f
SimpleString isomorphism!!!
ammario Mar 30, 2023
2844497
Support scalars
ammario Mar 30, 2023
4960df8
ComplexObjects work!
ammario Mar 30, 2023
2a2c926
golden files work!
ammario Mar 30, 2023
056437f
Fixup YAML types
ammario Mar 30, 2023
c2428ff
give default value in comment
ammario Mar 30, 2023
8b210dc
Merge remote-tracking branch 'origin/main' into yaml
ammario Mar 30, 2023
26d7f21
Merge remote-tracking branch 'origin/main' into yaml
ammario Mar 31, 2023
38fa539
Add values.YAMLConfigPath
ammario Mar 31, 2023
64b167a
Merge remote-tracking branch 'origin/main' into yaml
ammario Mar 31, 2023
7edea99
Add YAML to core clibase parsing
ammario Mar 31, 2023
3ab35c1
Server Test WIP
ammario Mar 31, 2023
38155da
More WIP
ammario Mar 31, 2023
451c149
Merge remote-tracking branch 'origin/main' into yaml
ammario Apr 1, 2023
c72f67c
hmm
ammario Apr 1, 2023
9d61ca7
Cant find a clean way to do this..
ammario Apr 4, 2023
5b61b7b
Mediocre solution
ammario Apr 4, 2023
4923d92
hmm
ammario Apr 4, 2023
b6f982c
Merge remote-tracking branch 'origin/main' into yaml
ammario Apr 4, 2023
781786b
New, better YAML
ammario Apr 6, 2023
b03999a
clibase passes
ammario Apr 6, 2023
d018838
Fix UnknownOptions errors
ammario Apr 6, 2023
fe93d7f
Work on nil normalization
ammario Apr 6, 2023
0af47bb
Server tests pass!
ammario Apr 6, 2023
4a1df77
Merge remote-tracking branch 'origin/main' into yaml
ammario Apr 6, 2023
64255b3
make gen + self review cleanup
ammario Apr 6, 2023
99d6068
Generate docs
ammario Apr 6, 2023
300484b
make gen
ammario Apr 6, 2023
4cf5a21
Add --debug-options
ammario Apr 6, 2023
abc92d9
Normalize golden files
ammario Apr 6, 2023
a958324
fix log path
ammario Apr 7, 2023
8ead9fc
minor fix
ammario Apr 7, 2023
6eb19f6
Fix mutability bug in PrepareAll
ammario Apr 7, 2023
f77460f
Address review comments
ammario Apr 7, 2023
4e63bd5
Merge remote-tracking branch 'origin/main' into yaml
ammario Apr 7, 2023
2a96c70
Fix windows?
ammario Apr 7, 2023
7ae7cad
Small improvements
ammario Apr 7, 2023
09d5a35
Reduce YAML ident to 2
ammario Apr 7, 2023
d6506c6
Log mystery error
ammario Apr 7, 2023
551e55d
fixup! Log mystery error
ammario Apr 7, 2023
c3f3317
ecdsa
ammario Apr 7, 2023
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
Prev Previous commit
Next Next commit
Normalize golden files
  • Loading branch information
ammario committed Apr 6, 2023
commit abc92d9f30732c49ca02539caf4ec0fa1cb9c924
60 changes: 33 additions & 27 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,7 @@ ExtractCommandPathsLoop:
actual = bytes.ReplaceAll(actual, []byte(k), []byte(v))
}

// Replace any timestamps with a placeholder.
actual = timestampRegex.ReplaceAll(actual, []byte("[timestamp]"))

homeDir, err := os.UserHomeDir()
require.NoError(t, err)

configDir := config.DefaultDir()
actual = bytes.ReplaceAll(actual, []byte(configDir), []byte("~/.config/coderv2"))

actual = bytes.ReplaceAll(actual, []byte(codersdk.DefaultCacheDir()), []byte("[cache dir]"))

// The home directory changes depending on the test environment.
actual = bytes.ReplaceAll(actual, []byte(homeDir), []byte("~"))

actual = normalizeGoldenFile(t, actual)
goldenPath := filepath.Join("testdata", strings.Replace(tt.name, " ", "_", -1)+".golden")
if *updateGoldenFiles {
t.Logf("update golden file for: %q: %s", tt.name, goldenPath)
Expand All @@ -131,19 +118,7 @@ ExtractCommandPathsLoop:
expected, err := os.ReadFile(goldenPath)
require.NoError(t, err, "read golden file, run \"make update-golden-files\" and commit the changes")

// Normalize files to tolerate different operating systems.
for _, r := range []struct {
old string
new string
}{
{"\r\n", "\n"},
{`~\.cache\coder`, "~/.cache/coder"},
{`C:\Users\RUNNER~1\AppData\Local\Temp`, "/tmp"},
{os.TempDir(), "/tmp"},
} {
expected = bytes.ReplaceAll(expected, []byte(r.old), []byte(r.new))
actual = bytes.ReplaceAll(actual, []byte(r.old), []byte(r.new))
}
expected = normalizeGoldenFile(t, expected)
require.Equal(
t, string(expected), string(actual),
"golden file mismatch: %s, run \"make update-golden-files\", verify and commit the changes",
Expand All @@ -153,6 +128,37 @@ ExtractCommandPathsLoop:
}
}

// normalizeGoldenFiles replaces any strings that are system or timing dependent
// with a placeholder so that the golden files can be compared with a simple
// equality check.
func normalizeGoldenFile(t *testing.T, byt []byte) []byte {
// Replace any timestamps with a placeholder.
byt = timestampRegex.ReplaceAll(byt, []byte("[timestamp]"))

homeDir, err := os.UserHomeDir()
require.NoError(t, err)

configDir := config.DefaultDir()
byt = bytes.ReplaceAll(byt, []byte(configDir), []byte("~/.config/coderv2"))

byt = bytes.ReplaceAll(byt, []byte(codersdk.DefaultCacheDir()), []byte("[cache dir]"))

// The home directory changes depending on the test environment.
byt = bytes.ReplaceAll(byt, []byte(homeDir), []byte("~"))
for _, r := range []struct {
old string
new string
}{
{"\r\n", "\n"},
{`~\.cache\coder`, "~/.cache/coder"},
{`C:\Users\RUNNER~1\AppData\Local\Temp`, "/tmp"},
{os.TempDir(), "/tmp"},
} {
byt = bytes.ReplaceAll(byt, []byte(r.old), []byte(r.new))
}
return byt
}

func extractVisibleCommandPaths(cmdPath []string, cmds []*clibase.Cmd) [][]string {
var cmdPaths [][]string
for _, c := range cmds {
Expand Down
1 change: 1 addition & 0 deletions cli/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ func TestServerYAMLConfig(t *testing.T) {

goldenPath := filepath.Join("testdata", "server-config.yaml.golden")

wantByt = normalizeGoldenFile(t, wantByt)
if *updateGoldenFiles {
require.NoError(t, os.WriteFile(goldenPath, wantByt, 0o600))
return
Expand Down
3 changes: 3 additions & 0 deletions cli/testdata/coder_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Coder v0.0.0-devel — A tool for provisioning self-hosted development environme
Global options are applied to all commands. They can be set using environment
variables or flags.

--debug-options bool
Print all options, how they're set, then exit.

--global-config string, $CODER_CONFIG_DIR (default: ~/.config/coderv2)
Path to the global `coder` config directory.

Expand Down
4 changes: 2 additions & 2 deletions cli/testdata/server-config.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ updateCheck: false
enableSwagger: false
# The directory to cache temporary files. If unspecified and $CACHE_DIRECTORY is
# set, it will be used for compatibility with systemd. (default:
# /home/coder/.cache/coder, type: string)
cacheDir: /home/coder/.cache/coder
# [cache dir], type: string)
cacheDir: [cache dir]
# Controls whether data will be stored in an in-memory database. (default:
# <unset>, type: bool)
inMemoryDatabase: false
Expand Down