Skip to content
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

Fix setting env name with a property #568

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions temporalcli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func NewCommandContext(ctx context.Context, options CommandOptions) (*CommandCon
return cctx, stop, nil
}

const temporalEnv = "TEMPORAL_ENV"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there's much value in making this a constant that is used in one place, but meh


func (c *CommandContext) preprocessOptions() error {
if len(c.Options.Args) == 0 {
c.Options.Args = os.Args[1:]
Expand Down Expand Up @@ -123,6 +125,9 @@ func (c *CommandContext) preprocessOptions() error {

if c.Options.EnvConfigName == "" {
c.Options.EnvConfigName = "default"
if envVal, ok := c.Options.LookupEnv(temporalEnv); ok {
c.Options.EnvConfigName = envVal
}
// Default to --env, prefetched from CLI args
for i, arg := range c.Options.Args {
if arg == "--env" && i+1 < len(c.Options.Args) {
Expand Down
15 changes: 15 additions & 0 deletions temporalcli/commands.workflow_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,21 @@ func (s *SharedServerSuite) TestWorkflow_Execute_EnvConfig() {
)
s.NoError(res.Err)
s.ContainsOnSameLine(res.Stdout.String(), "Result", `"env-conf-input"`)

// And we can specify `env` with a property
s.NoError(os.Setenv("TEMPORAL_ENV", "myenv"))
defer os.Unsetenv("TEMPORAL_ENV")
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to replace LookupEnv in the CLI options instead of using actual environment variables that affect everything globally. See TestWorkflow_Execute_EnvVars in commands.workflow_exec_test.go for an example (I saw we unfortunately have others not doing this in tests that should).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw that but I though using a system property "for real" may be a better test than faking it... Are there any side-effects of using a real system property in the test?

Copy link
Member

@cretz cretz May 20, 2024

Choose a reason for hiding this comment

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

This can damage our ability to do parallel tests in the future. Tests need to be as self-contained as possible. It's mocked out at the highest level, so you're not getting much more using the real env var I don't think.

res = s.Execute(
"workflow", "execute",
"--env-file", tmpFile.Name(),
"--address", s.Address(),
"--task-queue", s.Worker().Options.TaskQueue,
"--type", "DevWorkflow",
"--workflow-id", "my-id3",
)
s.NoError(res.Err)
s.ContainsOnSameLine(res.Stdout.String(), "Result", `"env-conf-input"`)

}

func (s *SharedServerSuite) TestWorkflow_Execute_CodecEndpoint() {
Expand Down
Loading