Skip to content

Commit

Permalink
Refactor: Change implementation of testing Go packages from project root
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdulsametileri committed Apr 18, 2022
1 parent 00ee972 commit ac9e0bf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/vx/cli/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"testing"

_ "github.com/Abdulsametileri/vX/testing"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 2 additions & 0 deletions cmd/vx/cli/checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cli
import (
"testing"

_ "github.com/Abdulsametileri/vX/testing"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions cmd/vx/cli/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

_ "github.com/Abdulsametileri/vX/testing"
"github.com/acarl005/stripansi"
"github.com/stretchr/testify/assert"
)
Expand Down
9 changes: 0 additions & 9 deletions cmd/vx/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package cli

import (
"log"
"os"
"time"

"github.com/spf13/cobra"
)

func init() {
changeWorkingDirectoryToRootDir()
changeGlobalTimeToUTC()
}

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/vx/cli/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"testing"

_ "github.com/Abdulsametileri/vX/testing"
"github.com/acarl005/stripansi"
"github.com/stretchr/testify/assert"
)
Expand Down
1 change: 1 addition & 0 deletions cmd/vx/cli/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"testing"

_ "github.com/Abdulsametileri/vX/testing"
"github.com/stretchr/testify/assert"
)

Expand Down
19 changes: 19 additions & 0 deletions testing/testing.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit ac9e0bf

Please sign in to comment.