From 97e992236a7249bf0a8b7fa815c744d92dde4089 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 20 Jan 2022 23:39:56 +0300 Subject: error on missing env if used Signed-off-by: Valery Piashchynski --- internal/cli/root.go | 5 ++++- internal/cli/root_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) 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..806669f7 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,51 @@ 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")) + }) +} -- cgit v1.2.3 From b088e7c92353ec49bde6631925d57d5f8fe8ea22 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 20 Jan 2022 23:44:58 +0300 Subject: update CHANGELOG Signed-off-by: Valery Piashchynski --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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: -- cgit v1.2.3 From 5a0835d5963c82275f23097ff17b41646348bb7e Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 20 Jan 2022 23:45:38 +0300 Subject: fix golangci linters warnings Signed-off-by: Valery Piashchynski --- internal/cli/root_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/cli/root_test.go b/internal/cli/root_test.go index 806669f7..602b9d3b 100644 --- a/internal/cli/root_test.go +++ b/internal/cli/root_test.go @@ -115,6 +115,7 @@ func TestCommandNoEnvFileNoError(t *testing.T) { require.NoError(t, err) f2, err := os.Create(path.Join(tmp, ".rr.yaml")) require.NoError(t, err) + defer func() { _ = f.Close() _ = f2.Close() -- cgit v1.2.3