Skip to content

Commit ac9e0bf

Browse files
Refactor: Change implementation of testing Go packages from project root
1 parent 00ee972 commit ac9e0bf

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

cmd/vx/cli/add_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"testing"
55

6+
_ "github.com/Abdulsametileri/vX/testing"
67
"github.com/stretchr/testify/assert"
78
)
89

cmd/vx/cli/checkout_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cli
33
import (
44
"testing"
55

6+
_ "github.com/Abdulsametileri/vX/testing"
7+
68
"github.com/stretchr/testify/assert"
79
)
810

cmd/vx/cli/history_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8+
_ "github.com/Abdulsametileri/vX/testing"
89
"github.com/acarl005/stripansi"
910
"github.com/stretchr/testify/assert"
1011
)

cmd/vx/cli/root.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ package cli
22

33
import (
44
"log"
5-
"os"
65
"time"
76

87
"github.com/spf13/cobra"
98
)
109

1110
func init() {
12-
changeWorkingDirectoryToRootDir()
1311
changeGlobalTimeToUTC()
1412
}
1513

@@ -30,13 +28,6 @@ func Execute() {
3028
}
3129
}
3230

33-
func changeWorkingDirectoryToRootDir() {
34-
err := os.Chdir("../../..")
35-
if err != nil {
36-
panic(err)
37-
}
38-
}
39-
4031
func changeGlobalTimeToUTC() {
4132
loc, err := time.LoadLocation("UTC")
4233
if err == nil {

cmd/vx/cli/status_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"testing"
66

7+
_ "github.com/Abdulsametileri/vX/testing"
78
"github.com/acarl005/stripansi"
89
"github.com/stretchr/testify/assert"
910
)

cmd/vx/cli/utils_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"testing"
55

6+
_ "github.com/Abdulsametileri/vX/testing"
67
"github.com/stretchr/testify/assert"
78
)
89

testing/testing.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package testing
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"runtime"
7+
)
8+
9+
func init() {
10+
changeWorkingDirectoryToRootDir()
11+
}
12+
13+
func changeWorkingDirectoryToRootDir() {
14+
_, filename, _, _ := runtime.Caller(0)
15+
err := os.Chdir(filepath.Join(filepath.Dir(filename), ".."))
16+
if err != nil {
17+
panic(err)
18+
}
19+
}

0 commit comments

Comments
 (0)