8000 feat: Read params from file for template/workspace creation by AbhineetJain · Pull Request #1541 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: Read params from file for template/workspace creation #1541

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 13 commits into from
May 20, 2022
Merged
Prev Previous commit
Next Next commit
Fix unit tests for windows
  • Loading branch information
AbhineetJain committed May 20, 2022
commit 1a12be1805bc3075691f51917ddb1f1840775f37
23 changes: 22 additions & 1 deletion cli/parameter_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"os"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -23,6 +24,8 @@ func TestCreateParameterMapFromFile(t *testing.T) {

assert.Equal(t, expectedMap, parameterMapFromFile)
assert.Nil(t, err)

removeTmpDirUntilSuccess(t)
})
t.Run("WithEmptyFilename", func(t *testing.T) {
t.Parallel()
Expand All @@ -38,7 +41,14 @@ func TestCreateParameterMapFromFile(t *testing.T) {
parameterMapFromFile, err := createParameterMapFromFile("invalidFile.yaml")

assert.Nil(t, parameterMapFromFile)
assert.EqualError(t, err, "open invalidFile.yaml: no such file or directory")

// On Unix based systems, it is: `open invalidFile.yaml: no such file or directory`
// On Windows, it is `open invalidFile.yaml: The system cannot find the file specified.`
if runtime.GOOS == "windows" {
assert.EqualError(t, err, "open invalidFile.yaml: The system cannot find the file specified.")
} else {
assert.EqualError(t, err, "open invalidFile.yaml: no such file or directory")
}
})
t.Run("WithInvalidYAML", func(t *testing.T) {
t.Parallel()
Expand All @@ -49,5 +59,16 @@ func TestCreateParameterMapFromFile(t *testing.T) {

assert.Nil(t, parameterMapFromFile)
assert.EqualError(t, err, "yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `region ...` into map[string]string")

removeTmpDirUntilSuccess(t)
})
}

func removeTmpDirUntilSuccess(t *testing.T) {
t.Cleanup(func() {
err := os.RemoveAll(t.TempDir())
for err != nil {
err = os.RemoveAll(t.TempDir())
}
})
}
0