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 all commits
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
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