diff --git a/cmd/vx/cli/add_test.go b/cmd/vx/cli/add_test.go index 07663ac..3f7618b 100644 --- a/cmd/vx/cli/add_test.go +++ b/cmd/vx/cli/add_test.go @@ -3,6 +3,7 @@ package cli import ( "testing" + _ "github.com/Abdulsametileri/vX/testing" "github.com/stretchr/testify/assert" ) diff --git a/cmd/vx/cli/checkout_test.go b/cmd/vx/cli/checkout_test.go index bfd703d..07326b4 100644 --- a/cmd/vx/cli/checkout_test.go +++ b/cmd/vx/cli/checkout_test.go @@ -3,6 +3,8 @@ package cli import ( "testing" + _ "github.com/Abdulsametileri/vX/testing" + "github.com/stretchr/testify/assert" ) diff --git a/cmd/vx/cli/history_test.go b/cmd/vx/cli/history_test.go index 2f0be71..456f318 100644 --- a/cmd/vx/cli/history_test.go +++ b/cmd/vx/cli/history_test.go @@ -5,6 +5,7 @@ import ( "fmt" "testing" + _ "github.com/Abdulsametileri/vX/testing" "github.com/acarl005/stripansi" "github.com/stretchr/testify/assert" ) diff --git a/cmd/vx/cli/root.go b/cmd/vx/cli/root.go index d43e62d..deadd42 100644 --- a/cmd/vx/cli/root.go +++ b/cmd/vx/cli/root.go @@ -2,14 +2,12 @@ package cli import ( "log" - "os" "time" "github.com/spf13/cobra" ) func init() { - changeWorkingDirectoryToRootDir() changeGlobalTimeToUTC() } @@ -30,13 +28,6 @@ func Execute() { } } -func changeWorkingDirectoryToRootDir() { - err := os.Chdir("../../..") - if err != nil { - panic(err) - } -} - func changeGlobalTimeToUTC() { loc, err := time.LoadLocation("UTC") if err == nil { diff --git a/cmd/vx/cli/status_test.go b/cmd/vx/cli/status_test.go index 25796dc..66fed8d 100644 --- a/cmd/vx/cli/status_test.go +++ b/cmd/vx/cli/status_test.go @@ -4,6 +4,7 @@ import ( "bytes" "testing" + _ "github.com/Abdulsametileri/vX/testing" "github.com/acarl005/stripansi" "github.com/stretchr/testify/assert" ) diff --git a/cmd/vx/cli/utils_test.go b/cmd/vx/cli/utils_test.go index 30d3514..4df8d35 100644 --- a/cmd/vx/cli/utils_test.go +++ b/cmd/vx/cli/utils_test.go @@ -3,6 +3,7 @@ package cli import ( "testing" + _ "github.com/Abdulsametileri/vX/testing" "github.com/stretchr/testify/assert" ) diff --git a/testing/testing.go b/testing/testing.go new file mode 100644 index 0000000..8104767 --- /dev/null +++ b/testing/testing.go @@ -0,0 +1,19 @@ +package testing + +import ( + "os" + "path/filepath" + "runtime" +) + +func init() { + changeWorkingDirectoryToRootDir() +} + +func changeWorkingDirectoryToRootDir() { + _, filename, _, _ := runtime.Caller(0) + err := os.Chdir(filepath.Join(filepath.Dir(filename), "..")) + if err != nil { + panic(err) + } +}