Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get current dir error #2283

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 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,8 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
"os/exec"
"os"
"path"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to consider separate path for Windows? Ref https://pkg.go.dev/path#pkg-overview, the path package does not support Windows path.

 This package does not deal with Windows paths with drive letters or backslashes;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, use filepath instead, thks for your check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaunist backend-e2e-test error, click

can you check it and rerun? thks

"strings"
"testing"

Expand Down Expand Up @@ -89,22 +90,21 @@ 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
apiDir := path.Join(strings.Split(pwd,"/api/")[0], "/api/")
fileContent, err := ioutil.ReadFile(path.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 +139,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