Skip to content
New issue

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

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

Already on GitHub? # to your account

More env tests #454

Merged
merged 2 commits into from
Feb 14, 2024
Merged
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
52 changes: 42 additions & 10 deletions temporalcli/commands.env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@ import (
"gopkg.in/yaml.v3"
)

// TODO(cretz): To test:
// * Env var actually sets CLI arg
Copy link
Member Author

Choose a reason for hiding this comment

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

Env var tests were previously added with the workflow tests (i.e. TestWorkflow_Execute_EnvVars)

// * Get single and all for env
// * Delete single and all for env
// * List envs

func TestEnv_Simple(t *testing.T) {
h := NewCommandHarness(t)
defer h.Close()

// Non-existent file, no env found for get
h.Options.EnvConfigFile = "does-not-exist"
res := h.Execute("env", "get", "myenv")
h.ErrorContains(res.Err, `env "myenv" not found`)
res := h.Execute("env", "get", "myenv1")
h.ErrorContains(res.Err, `env "myenv1" not found`)

// Temp file for env
tmpFile, err := os.CreateTemp("", "")
Expand All @@ -29,12 +23,50 @@ func TestEnv_Simple(t *testing.T) {
defer os.Remove(h.Options.EnvConfigFile)

// Store a key
res = h.Execute("env", "set", "myenv.foo", "bar")
res = h.Execute("env", "set", "myenv1.foo", "bar")
h.NoError(res.Err)
// Confirm file is YAML with expected values
b, err := os.ReadFile(h.Options.EnvConfigFile)
h.NoError(err)
var yamlVals map[string]map[string]map[string]string
h.NoError(yaml.Unmarshal(b, &yamlVals))
h.Equal("bar", yamlVals["env"]["myenv"]["foo"])
h.Equal("bar", yamlVals["env"]["myenv1"]["foo"])

// Store another key and another env
res = h.Execute("env", "set", "myenv1.baz", "qux")
h.NoError(res.Err)
res = h.Execute("env", "set", "myenv2.foo", "baz")
h.NoError(res.Err)

// Get single prop
res = h.Execute("env", "get", "myenv1.baz")
h.NoError(res.Err)
h.ContainsOnSameLine(res.Stdout.String(), "baz", "qux")
h.NotContains(res.Stdout.String(), "foo")

// Get all props for env
res = h.Execute("env", "get", "myenv1")
h.NoError(res.Err)
h.ContainsOnSameLine(res.Stdout.String(), "foo", "bar")
h.ContainsOnSameLine(res.Stdout.String(), "baz", "qux")

// List envs
res = h.Execute("env", "list")
h.NoError(res.Err)
h.Contains(res.Stdout.String(), "myenv1")
h.Contains(res.Stdout.String(), "myenv2")

// Delete single env value
res = h.Execute("env", "delete", "myenv1.foo")
h.NoError(res.Err)
res = h.Execute("env", "get", "myenv1")
h.NoError(res.Err)
h.NotContains(res.Stdout.String(), "foo")

// Delete entire env
res = h.Execute("env", "delete", "myenv2")
h.NoError(res.Err)
res = h.Execute("env", "list")
h.NoError(res.Err)
h.NotContains(res.Stdout.String(), "myenv2")
}
Loading