Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix env resolution priority Fixes #269 * Defer GO_ENV rollback only once
- Loading branch information
1 parent
9c88834
commit d1727d5
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_RootCmd_NoArg(t *testing.T) { | ||
oldEnv := os.Getenv("GO_ENV") | ||
defer os.Setenv("GO_ENV", oldEnv) | ||
|
||
// Fallback on default env | ||
r := require.New(t) | ||
c := RootCmd | ||
c.SetArgs([]string{}) | ||
err := c.Execute() | ||
r.NoError(err) | ||
r.Equal("development", env) | ||
|
||
// Override with GO_ENV | ||
c.SetArgs([]string{}) | ||
os.Setenv("GO_ENV", "test") | ||
err = c.Execute() | ||
r.NoError(err) | ||
r.Equal("test", env) | ||
|
||
// CLI flag priority | ||
c.SetArgs([]string{ | ||
"--env", | ||
"production", | ||
}) | ||
os.Setenv("GO_ENV", "test") | ||
err = c.Execute() | ||
r.NoError(err) | ||
r.Equal("production", env) | ||
} |