This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new e0d92c4  fix:get current dir error (#2283)
e0d92c4 is described below

commit e0d92c493a5ba6bb12217be5c77bd03d654d6412
Author: LetsGO <[email protected]>
AuthorDate: Wed Jan 12 16:01:17 2022 +0800

    fix:get current dir error (#2283)
---
 .../handler/data_loader/route_import_test.go       | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/api/internal/handler/data_loader/route_import_test.go 
b/api/internal/handler/data_loader/route_import_test.go
index 50f76f7..81cbad8 100644
--- a/api/internal/handler/data_loader/route_import_test.go
+++ b/api/internal/handler/data_loader/route_import_test.go
@@ -23,7 +23,9 @@ import (
        "io/ioutil"
        "mime/multipart"
        "net/http"
-       "os/exec"
+       "os"
+       "path/filepath"
+       "runtime"
        "strings"
        "testing"
 
@@ -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) {
@@ -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) {

Reply via email to