From 1327ad09b6177ebb6ec88e21152e2c413c23ac5b Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Fri, 20 Dec 2024 17:43:12 +0200 Subject: [PATCH] Run tests on Windows and MacOS - Extend the CI workflow to test on Windows and MacOS - Add missing Close() calls when opening the temporary test files - Fix test with relative paths on different drives. On the Windows GitHub runners the cache directory is on drive C and the current working directory is on drive D which makes the relative path resolution fail. --- .github/workflows/ci.yaml | 60 +++++++++++++++---- .gitignore | 3 +- main_test.go | 8 ++- plugin/digitizer/digitizer_plugin_test.go | 8 ++- .../orchestrator/orchestrator_plugin_test.go | 8 ++- test/execution_test.go | 4 +- test/setup.go | 20 ++++++- utils/file_stream_test.go | 2 + 8 files changed, 93 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cda25f8..0aab6fe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,6 +3,7 @@ on: [push] env: UIPATHCLI_BASE_VERSION: "v1.1" + GO_VERSION: "1.22.2" jobs: build: @@ -17,7 +18,7 @@ jobs: - name: Setup go uses: actions/setup-go@v5 with: - go-version: '1.22.2' + go-version: ${{ env.GO_VERSION }} cache: true - name: Version id: version @@ -25,14 +26,31 @@ jobs: UIPATHCLI_VERSION=$(./version.sh "$UIPATHCLI_BASE_VERSION") echo "UIPATHCLI_VERSION=$(echo $UIPATHCLI_VERSION)" >> $GITHUB_ENV echo "UIPATHCLI_VERSION=$(echo $UIPATHCLI_VERSION)" >> $GITHUB_OUTPUT - - name: Install dependencies - run: go get . - name: Build run: go build -ldflags="-X github.com/UiPath/uipathcli/commandline.Version=$UIPATHCLI_VERSION" . - name: Lint run: | go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 golangci-lint run + - name: Package + run: ./build.sh && ./package.sh + - name: Upload packages + uses: actions/upload-artifact@v4 + with: + name: packages + path: build/packages/ + if-no-files-found: error + + test_linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true - name: Test run: go test -coverprofile="coverage.out" -coverpkg "$(go list github.com/UiPath/uipathcli/... | grep -v 'test' | tr '\n' ',')" ./... - name: Coverage @@ -41,17 +59,35 @@ jobs: run: | go install github.com/mattn/goveralls@latest goveralls -coverprofile="coverage.out" -service="github" - - name: Package - run: ./build.sh && ./package.sh - - name: Upload packages - uses: actions/upload-artifact@v4 + + test_windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 with: - name: packages - path: build/packages/ - if-no-files-found: error + go-version: ${{ env.GO_VERSION }} + cache: true + - name: Test + run: go test ./... + + test_macos: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + - name: Test + run: go test ./... publish_pages: - needs: build + needs: [build, test_linux, test_windows, test_macos] permissions: pages: write id-token: write @@ -79,7 +115,7 @@ jobs: uses: actions/deploy-pages@v4 release: - needs: build + needs: [build, test_linux, test_windows, test_macos] if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest env: diff --git a/.gitignore b/.gitignore index e322683..90b4b46 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ uipathcli build/ coverage.out coverage.html -bin/ \ No newline at end of file +bin/ +tmp/ \ No newline at end of file diff --git a/main_test.go b/main_test.go index c14ea71..3e6cd8a 100644 --- a/main_test.go +++ b/main_test.go @@ -213,7 +213,13 @@ func createFile(t *testing.T, directory string, name string) string { if err != nil { t.Fatal(err) } - t.Cleanup(func() { os.Remove(tempFile.Name()) }) + defer tempFile.Close() + t.Cleanup(func() { + err := os.Remove(tempFile.Name()) + if err != nil { + t.Fatal(err) + } + }) return tempFile.Name() } diff --git a/plugin/digitizer/digitizer_plugin_test.go b/plugin/digitizer/digitizer_plugin_test.go index d60129c..37d55ff 100644 --- a/plugin/digitizer/digitizer_plugin_test.go +++ b/plugin/digitizer/digitizer_plugin_test.go @@ -381,7 +381,13 @@ func createFile(t *testing.T) string { if err != nil { t.Fatal(err) } - t.Cleanup(func() { os.Remove(tempFile.Name()) }) + defer tempFile.Close() + t.Cleanup(func() { + err := os.Remove(tempFile.Name()) + if err != nil { + t.Fatal(err) + } + }) return tempFile.Name() } diff --git a/plugin/orchestrator/orchestrator_plugin_test.go b/plugin/orchestrator/orchestrator_plugin_test.go index d77c470..6fcd320 100644 --- a/plugin/orchestrator/orchestrator_plugin_test.go +++ b/plugin/orchestrator/orchestrator_plugin_test.go @@ -504,7 +504,13 @@ func createFile(t *testing.T) string { if err != nil { t.Fatal(err) } - t.Cleanup(func() { os.Remove(tempFile.Name()) }) + defer tempFile.Close() + t.Cleanup(func() { + err := os.Remove(tempFile.Name()) + if err != nil { + t.Fatal(err) + } + }) return tempFile.Name() } diff --git a/test/execution_test.go b/test/execution_test.go index 05122fc..1ff476d 100644 --- a/test/execution_test.go +++ b/test/execution_test.go @@ -1288,10 +1288,10 @@ paths: WithResponse(200, ""). Build() - path := createFile(t) + currentPath, _ := os.Getwd() + path := createFileInFolder(t, filepath.Join(currentPath, "tmp")) writeFile(t, path, []byte("hello-world")) - currentPath, _ := os.Getwd() relativePath, _ := filepath.Rel(currentPath, path) result := RunCli([]string{"myservice", "upload", "--file", relativePath}, context) diff --git a/test/setup.go b/test/setup.go index 6d7d989..46809f0 100644 --- a/test/setup.go +++ b/test/setup.go @@ -229,11 +229,27 @@ func RunCli(args []string, context Context) Result { } func createFile(t *testing.T) string { - tempFile, err := os.CreateTemp("", "uipath-test") + return createFileInFolder(t, "") +} + +func createFileInFolder(t *testing.T, path string) string { + if path != "" { + err := os.MkdirAll(path, 0700) + if err != nil { + t.Fatal(err) + } + } + tempFile, err := os.CreateTemp(path, "uipath-test") if err != nil { t.Fatal(err) } - t.Cleanup(func() { os.Remove(tempFile.Name()) }) + defer tempFile.Close() + t.Cleanup(func() { + err := os.Remove(tempFile.Name()) + if err != nil { + t.Fatal(err) + } + }) return tempFile.Name() } diff --git a/utils/file_stream_test.go b/utils/file_stream_test.go index 092d9c4..9477c2b 100644 --- a/utils/file_stream_test.go +++ b/utils/file_stream_test.go @@ -18,6 +18,7 @@ func TestFileStreamName(t *testing.T) { func TestFileStreamSize(t *testing.T) { tempFile, _ := os.CreateTemp("", "uipath-test") + defer tempFile.Close() t.Cleanup(func() { os.Remove(tempFile.Name()) }) err := os.WriteFile(tempFile.Name(), []byte("hello-world"), 0600) if err != nil { @@ -37,6 +38,7 @@ func TestFileStreamSize(t *testing.T) { func TestFileStreamData(t *testing.T) { tempFile, _ := os.CreateTemp("", "uipath-test") + defer tempFile.Close() t.Cleanup(func() { os.Remove(tempFile.Name()) }) err := os.WriteFile(tempFile.Name(), []byte("hello-world"), 0600) if err != nil {