From 32649021314ea85501b3e4fa1061cf44d0925455 Mon Sep 17 00:00:00 2001 From: Chen-I Lim <46905241+chenilim@users.noreply.github.com> Date: Wed, 13 Apr 2022 10:17:04 -0700 Subject: [PATCH] Fix #2770: Handle Windows path in import and tests (#2771) * Upgrade npm in build-ubuntu * npm i -S moment * Don't upgrade npm * macos-latest on build-mac * Update dev-release.yml * Support Windows in import archive and tests * Run CI on Windows too * CI: Windows SQLite only * Remove npm ci fromn Windows CI --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ server/app/files_test.go | 15 +++++++++------ server/app/import.go | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b29fb325a..900a22315 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,3 +81,23 @@ jobs: - name: "Test webapp: Cypress" run: "cd webapp; npm run cypress:ci" + + ci-windows-server: + runs-on: windows-2022 + + strategy: + matrix: + db: + - sqlite + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: "Test server: ${{matrix['db']}}" + run: make server-test-${{matrix['db']}} diff --git a/server/app/files_test.go b/server/app/files_test.go index 44ea15058..9c47a115d 100644 --- a/server/app/files_test.go +++ b/server/app/files_test.go @@ -2,6 +2,8 @@ package app import ( "io" + "os" + "path/filepath" "strings" "testing" @@ -15,7 +17,6 @@ import ( const ( testFileName = "temp-file-name" testBoardID = "test-board-id" - testFilePath = "1/test-board-id/temp-file-name" ) type TestError struct{} @@ -23,6 +24,8 @@ type TestError struct{} func (err *TestError) Error() string { return "Mocked File backend error" } func TestGetFileReader(t *testing.T) { + testFilePath := filepath.Join("1", "test-board-id", "temp-file-name") + th, _ := SetupTestHelper(t) mockedReadCloseSeek := &mocks.ReadCloseSeeker{} t.Run("should get file reader from filestore successfully", func(t *testing.T) { @@ -105,7 +108,7 @@ func TestGetFileReader(t *testing.T) { }) t.Run("should move file from old filepath to new filepath, if file doesnot exists in new filepath and workspace id is 0", func(t *testing.T) { - filePath := "0/test-board-id/temp-file-name" + filePath := filepath.Join("0", "test-board-id", "temp-file-name") workspaceid := "0" mockedFileBackend := &mocks.FileBackend{} th.App.filesBackend = mockedFileBackend @@ -140,7 +143,7 @@ func TestGetFileReader(t *testing.T) { }) t.Run("should return file reader, if file doesnot exists in new filepath and old file path", func(t *testing.T) { - filePath := "0/test-board-id/temp-file-name" + filePath := filepath.Join("0", "test-board-id", "temp-file-name") fileName := testFileName workspaceid := "0" mockedFileBackend := &mocks.FileBackend{} @@ -185,7 +188,7 @@ func TestSaveFile(t *testing.T) { th.App.filesBackend = mockedFileBackend writeFileFunc := func(reader io.Reader, path string) int64 { - paths := strings.Split(path, "/") + paths := strings.Split(path, string(os.PathSeparator)) assert.Equal(t, "1", paths[0]) assert.Equal(t, testBoardID, paths[1]) fileName = paths[2] @@ -208,7 +211,7 @@ func TestSaveFile(t *testing.T) { th.App.filesBackend = mockedFileBackend writeFileFunc := func(reader io.Reader, path string) int64 { - paths := strings.Split(path, "/") + paths := strings.Split(path, string(os.PathSeparator)) assert.Equal(t, "1", paths[0]) assert.Equal(t, "test-board-id", paths[1]) assert.Equal(t, "jpg", strings.Split(paths[2], ".")[1]) @@ -232,7 +235,7 @@ func TestSaveFile(t *testing.T) { mockedError := &TestError{} writeFileFunc := func(reader io.Reader, path string) int64 { - paths := strings.Split(path, "/") + paths := strings.Split(path, string(os.PathSeparator)) assert.Equal(t, "1", paths[0]) assert.Equal(t, "test-board-id", paths[1]) assert.Equal(t, "jpg", strings.Split(paths[2], ".")[1]) diff --git a/server/app/import.go b/server/app/import.go index 945f5b077..505b13e8f 100644 --- a/server/app/import.go +++ b/server/app/import.go @@ -58,7 +58,7 @@ func (a *App) ImportArchive(r io.Reader, opt model.ImportArchiveOptions) error { return err } - dir, filename := path.Split(hdr.Name) + dir, filename := filepath.Split(hdr.Name) dir = path.Clean(dir) switch filename {