diff options
author | Valery Piashchynski <[email protected]> | 2022-01-21 00:42:09 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2022-01-21 00:42:09 +0300 |
commit | cb0a07e57e041a8b4186b068dfcac709fe733d7a (patch) | |
tree | 1af729b621c21d2aee390ac84b94a44e23be2742 | |
parent | cf8037d3d87d20f94945b3988e1e7cfc98583ae5 (diff) | |
parent | 5a0835d5963c82275f23097ff17b41646348bb7e (diff) |
[#955]: feat(env): error on missing `.env` file
-rw-r--r-- | CHANGELOG.md | 9 | ||||
-rw-r--r-- | internal/cli/root.go | 5 | ||||
-rw-r--r-- | internal/cli/root_test.go | 52 |
3 files changed, 65 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 356fb662..f7c24f7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +## 2.7.4 (27.01.2022) + +## 👀 New: + +- ✏️ Return an error if the user uses the `.env` file, but it doesn't exist. [BUG](https://github.com/roadrunner-server/roadrunner/issues/954), (reporter @O00O0O) +- ✏️ Parallel workers allocation withing the plugin. [FR](https://github.com/roadrunner-server/roadrunner/issues/951), (reporter @roquie) + +--- + ## 2.7.3 (19.01.2022) ## 🩹 Fixes: diff --git a/internal/cli/root.go b/internal/cli/root.go index 29fd14b8..723e8a01 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -60,7 +60,10 @@ func NewCommand(cmdName string) *cobra.Command { //nolint:funlen } if dotenv != "" { - _ = godotenv.Load(dotenv) // error ignored because dotenv is optional feature + err := godotenv.Load(dotenv) + if err != nil { + return err + } } cfg := &config.Plugin{Path: cfgFile, Prefix: "rr", Flags: override} diff --git a/internal/cli/root_test.go b/internal/cli/root_test.go index 28e7d237..602b9d3b 100644 --- a/internal/cli/root_test.go +++ b/internal/cli/root_test.go @@ -1,9 +1,12 @@ package cli_test import ( + "os" + "path" "testing" "github.com/roadrunner-server/roadrunner/v2/internal/cli" + "github.com/stretchr/testify/require" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" @@ -83,3 +86,52 @@ func TestCommandSimpleExecuting(t *testing.T) { assert.NoError(t, cmd.Execute()) assert.True(t, executed) } + +func TestCommandNoEnvFileError(t *testing.T) { + cmd := cli.NewCommand("unit test") + cmd.SetArgs([]string{"-c", "./../../.rr.yaml", "--dotenv", "foo/bar"}) + + var executed bool + + if cmd.Run == nil { // override "Run" property for test (if it was not set) + cmd.Run = func(cmd *cobra.Command, args []string) { + executed = true + } + } + + assert.Error(t, cmd.Execute()) + assert.False(t, executed) +} + +func TestCommandNoEnvFileNoError(t *testing.T) { + tmp := os.TempDir() + + cmd := cli.NewCommand("unit test") + cmd.SetArgs([]string{"-c", path.Join(tmp, ".rr.yaml"), "--dotenv", path.Join(tmp, ".env")}) + + var executed bool + + f, err := os.Create(path.Join(tmp, ".env")) + require.NoError(t, err) + f2, err := os.Create(path.Join(tmp, ".rr.yaml")) + require.NoError(t, err) + + defer func() { + _ = f.Close() + _ = f2.Close() + }() + + if cmd.Run == nil { // override "Run" property for test (if it was not set) + cmd.Run = func(cmd *cobra.Command, args []string) { + executed = true + } + } + + assert.NoError(t, cmd.Execute()) + assert.True(t, executed) + + t.Cleanup(func() { + _ = os.RemoveAll(path.Join(tmp, ".env")) + _ = os.RemoveAll(path.Join(tmp, ".rr.yaml")) + }) +} |