Skip to content

Commit

Permalink
fix:get current dir error (#2283)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwrookie authored Jan 12, 2022
1 parent 8919bd7 commit e0d92c4
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions api/internal/handler/data_loader/route_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
"os/exec"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -89,22 +91,25 @@ func TestImport_invalid_content(t *testing.T) {
}

func ReadFile(t *testing.T, filePath string) []byte {
cmd := exec.Command("pwd")
pwdByte, err := cmd.CombinedOutput()
pwd := string(pwdByte)
pwd = strings.Replace(pwd, "\n", "", 1)
dir := pwd[:strings.Index(pwd, "/api/")] + "/api/"
bytes, err := ioutil.ReadFile(dir + filePath)
pwd, err := os.Getwd()
assert.Nil(t, err)

return bytes
bound := "/api/"
if runtime.GOOS == "windows" {
bound = `\api\`
}
apiDir := filepath.Join(strings.Split(pwd,bound)[0], bound)
fileContent, err := ioutil.ReadFile(filepath.Join(apiDir, filePath))
assert.Nil(t, err)

return fileContent
}

func TestImport_with_service_id(t *testing.T) {
bytes := ReadFile(t, "test/testdata/import/with-service-id.yaml")
fileContent := ReadFile(t, "test/testdata/import/with-service-id.yaml")
input := &ImportInput{}
input.FileName = "file1.json"
input.FileContent = bytes
input.FileContent = fileContent

mStore := &store.MockInterface{}
mStore.On("Get", mock.Anything).Run(func(args mock.Arguments) {
Expand Down Expand Up @@ -139,10 +144,10 @@ func TestImport_with_service_id(t *testing.T) {
}

func TestImport_with_upstream_id(t *testing.T) {
bytes := ReadFile(t, "test/testdata/import/with-upstream-id.yaml")
fileContent := ReadFile(t, "test/testdata/import/with-upstream-id.yaml")
input := &ImportInput{}
input.FileName = "file1.json"
input.FileContent = bytes
input.FileContent = fileContent

mStore := &store.MockInterface{}
mStore.On("Get", mock.Anything).Run(func(args mock.Arguments) {
Expand Down

0 comments on commit e0d92c4

Please sign in to comment.