summaryrefslogtreecommitdiff
path: root/internal/cli/root_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/root_test.go')
-rw-r--r--internal/cli/root_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/cli/root_test.go b/internal/cli/root_test.go
index 602b9d3b..f77acec3 100644
--- a/internal/cli/root_test.go
+++ b/internal/cli/root_test.go
@@ -135,3 +135,33 @@ func TestCommandNoEnvFileNoError(t *testing.T) {
_ = os.RemoveAll(path.Join(tmp, ".rr.yaml"))
})
}
+
+func TestCommandWorkingDir(t *testing.T) {
+ tmp := os.TempDir()
+
+ cmd := cli.NewCommand("serve")
+ cmd.SetArgs([]string{"-w", tmp})
+
+ var executed bool
+
+ var wd string
+
+ f2, err := os.Create(path.Join(tmp, ".rr.yaml"))
+ require.NoError(t, err)
+
+ if cmd.Run == nil { // override "Run" property for test (if it was not set)
+ cmd.Run = func(cmd *cobra.Command, args []string) {
+ executed = true
+ wd, _ = os.Getwd()
+ }
+ }
+
+ assert.NoError(t, cmd.Execute())
+ assert.True(t, executed)
+ assert.Equal(t, "/tmp", wd)
+
+ t.Cleanup(func() {
+ _ = f2.Close()
+ _ = os.RemoveAll(path.Join(tmp, ".rr.yaml"))
+ })
+}