Skip to content

Commit

Permalink
Test on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
thschmitt committed Dec 20, 2024
1 parent 958250b commit 0dbeedf
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 110 deletions.
42 changes: 33 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ jobs:
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
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: '1.22.2'
cache: true
- name: Test
run: go test -coverprofile="coverage.out" -coverpkg "$(go list github.com/UiPath/uipathcli/... | grep -v 'test' | tr '\n' ',')" ./...
- name: Coverage
Expand All @@ -41,17 +60,22 @@ 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: '1.22.2'
cache: true
- name: Test
run: go test ./...

publish_pages:
needs: build
needs: [build, test_linux, test_windows]
permissions:
pages: write
id-token: write
Expand Down Expand Up @@ -79,7 +103,7 @@ jobs:
uses: actions/deploy-pages@v4

release:
needs: build
needs: [build, test_linux, test_windows]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
Expand Down
101 changes: 0 additions & 101 deletions plugin/studio/studio_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,48 +135,6 @@ func TestPackCrossPlatformSuccessfully(t *testing.T) {
}
}

func TestPackWindowsSuccessfully(t *testing.T) {
context := test.NewContextBuilder().
WithDefinition("studio", studioDefinition).
WithCommandPlugin(NewPackagePackCommand()).
Build()

source := studioWindowsProjectDirectory()
destination := createDirectory(t)
result := test.RunCli([]string{"studio", "package", "pack", "--source", source, "--destination", destination}, context)

stdout := map[string]interface{}{}
err := json.Unmarshal([]byte(result.StdOut), &stdout)
if err != nil {
t.Errorf("Failed to deserialize pack command result: %v", err)
}
if stdout["status"] != "Succeeded" {
t.Errorf("Expected status to be Succeeded, but got: %v", result.StdOut)
}
if stdout["error"] != nil {
t.Errorf("Expected error to be nil, but got: %v", result.StdOut)
}
if stdout["name"] != "MyWindowsProcess" {
t.Errorf("Expected name to be set, but got: %v", result.StdOut)
}
if stdout["description"] != "Blank Process" {
t.Errorf("Expected version to be set, but got: %v", result.StdOut)
}
if stdout["projectId"] != "94c4c9c1-68c3-45d4-be14-d4427f17eddd" {
t.Errorf("Expected projectId to be set, but got: %v", result.StdOut)
}
if stdout["version"] != "1.0.0" {
t.Errorf("Expected version to be set, but got: %v", result.StdOut)
}
outputFile := stdout["output"].(string)
if outputFile != filepath.Join(destination, "MyWindowsProcess.1.0.0.nupkg") {
t.Errorf("Expected output path to be set, but got: %v", result.StdOut)
}
if _, err := os.Stat(outputFile); err != nil {
t.Errorf("Expected output file %s to exists, but could not find it: %v", outputFile, err)
}
}

func TestPackWithAutoVersionArgument(t *testing.T) {
commandName := ""
commandArgs := []string{}
Expand Down Expand Up @@ -446,60 +404,6 @@ func TestAnalyzeCrossPlatformSuccessfully(t *testing.T) {
}
}

func TestAnalyzeWindowsSuccessfully(t *testing.T) {
context := test.NewContextBuilder().
WithDefinition("studio", studioDefinition).
WithCommandPlugin(NewPackageAnalyzeCommand()).
Build()

source := studioWindowsProjectDirectory()
result := test.RunCli([]string{"studio", "package", "analyze", "--source", source}, context)

stdout := map[string]interface{}{}
err := json.Unmarshal([]byte(result.StdOut), &stdout)
if err != nil {
t.Errorf("Failed to deserialize analyze command result: %v", err)
}
if stdout["status"] != "Succeeded" {
t.Errorf("Expected status to be Succeeded, but got: %v", result.StdOut)
}
if stdout["error"] != nil {
t.Errorf("Expected error to be nil, but got: %v", result.StdOut)
}
violations := stdout["violations"].([]interface{})
if len(violations) == 0 {
t.Errorf("Expected violations not to be empty, but got: %v", result.StdOut)
}
violation := findViolation(violations, "TA-DBP-002")
if violation == nil {
t.Errorf("Could not find violation TA-DBP-002, got: %v", result.StdOut)
}
if violation["activityDisplayName"] != "" {
t.Errorf("Expected violation to have a activityDisplayName, but got: %v", result.StdOut)
}
if violation["description"] != "Workflow Main.xaml does not have any assigned Test Cases." {
t.Errorf("Expected violation to have a description, but got: %v", result.StdOut)
}
if violation["documentationLink"] != "https://docs.uipath.com/activities/lang-en/docs/ta-dbp-002" {
t.Errorf("Expected violation to have a documentationLink, but got: %v", result.StdOut)
}
if violation["errorSeverity"] != 1.0 {
t.Errorf("Expected violation to have a errorSeverity, but got: %v", result.StdOut)
}
if violation["filePath"] != "" {
t.Errorf("Expected violation to have a filePath, but got: %v", result.StdOut)
}
if violation["recommendation"] != "Creating Test Cases for your workflows allows you to run them frequently to discover potential issues early on before they are introduced in your production environment. [Learn more.](https://docs.uipath.com/activities/lang-en/docs/ta-dbp-002)" {
t.Errorf("Expected violation to have a recommendation, but got: %v", result.StdOut)
}
if violation["ruleName"] != "Untested Workflows" {
t.Errorf("Expected violation to have a ruleName, but got: %v", result.StdOut)
}
if violation["workflowDisplayName"] != "Main" {
t.Errorf("Expected violation to have a workflowDisplayName, but got: %v", result.StdOut)
}
}

func TestFailedAnalyzeReturnsFailureStatus(t *testing.T) {
exec := utils.NewExecCustomProcess(1, "Analyze output", "There was an error", func(name string, args []string) {})
context := test.NewContextBuilder().
Expand Down Expand Up @@ -587,11 +491,6 @@ func studioCrossPlatformProjectDirectory() string {
return filepath.Join(filepath.Dir(filename), "projects", "crossplatform")
}

func studioWindowsProjectDirectory() string {
_, filename, _, _ := runtime.Caller(0)
return filepath.Join(filepath.Dir(filename), "projects", "windows")
}

func createDirectory(t *testing.T) string {
tmp, err := os.MkdirTemp("", "uipath-test")
if err != nil {
Expand Down
112 changes: 112 additions & 0 deletions plugin/studio/studio_plugin_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//go:build windows

package studio

import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/UiPath/uipathcli/test"
)

const emptyStudioDefinition = `
openapi: 3.0.1
info:
title: UiPath Studio
description: UiPath Studio
version: v1
servers:
- url: https://cloud.uipath.com/{organization}/studio_/backend
description: The production url
variables:
organization:
description: The organization name (or id)
default: my-org
paths:
{}
`

func TestPackWindowsSuccessfully(t *testing.T) {
context := test.NewContextBuilder().
WithDefinition("studio", emptyStudioDefinition).
WithCommandPlugin(NewPackagePackCommand()).
Build()

source := studioWindowsProjectDirectory()
destination := createTempDirectory(t)
result := test.RunCli([]string{"studio", "package", "pack", "--source", source, "--destination", destination}, context)

stdout := map[string]interface{}{}
err := json.Unmarshal([]byte(result.StdOut), &stdout)
if err != nil {
t.Errorf("Failed to deserialize pack command result: %v", err)
}
if stdout["status"] != "Succeeded" {
t.Errorf("Expected status to be Succeeded, but got: %v", result.StdOut)
}
if stdout["error"] != nil {
t.Errorf("Expected error to be nil, but got: %v", result.StdOut)
}
if stdout["name"] != "MyWindowsProcess" {
t.Errorf("Expected name to be set, but got: %v", result.StdOut)
}
if stdout["description"] != "Blank Process" {
t.Errorf("Expected version to be set, but got: %v", result.StdOut)
}
if stdout["projectId"] != "94c4c9c1-68c3-45d4-be14-d4427f17eddd" {
t.Errorf("Expected projectId to be set, but got: %v", result.StdOut)
}
if stdout["version"] != "1.0.0" {
t.Errorf("Expected version to be set, but got: %v", result.StdOut)
}
outputFile := stdout["output"].(string)
if outputFile != filepath.Join(destination, "MyWindowsProcess.1.0.0.nupkg") {
t.Errorf("Expected output path to be set, but got: %v", result.StdOut)
}
if _, err := os.Stat(outputFile); err != nil {
t.Errorf("Expected output file %s to exists, but could not find it: %v", outputFile, err)
}
}

func TestAnalyzeWindowsSuccessfully(t *testing.T) {
context := test.NewContextBuilder().
WithDefinition("studio", emptyStudioDefinition).
WithCommandPlugin(NewPackageAnalyzeCommand()).
Build()

source := studioWindowsProjectDirectory()
result := test.RunCli([]string{"studio", "package", "analyze", "--source", source}, context)

stdout := map[string]interface{}{}
err := json.Unmarshal([]byte(result.StdOut), &stdout)
if err != nil {
t.Errorf("Failed to deserialize analyze command result: %v", err)
}
if stdout["status"] != "Succeeded" {
t.Errorf("Expected status to be Succeeded, but got: %v", result.StdOut)
}
if stdout["error"] != nil {
t.Errorf("Expected error to be nil, but got: %v", result.StdOut)
}
violations := stdout["violations"].([]interface{})
if len(violations) == 0 {
t.Errorf("Expected violations not to be empty, but got: %v", result.StdOut)
}
}

func studioWindowsProjectDirectory() string {
_, filename, _, _ := runtime.Caller(0)
return filepath.Join(filepath.Dir(filename), "projects", "windows")
}

func createTempDirectory(t *testing.T) string {
tmp, err := os.MkdirTemp("", "uipath-test")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.RemoveAll(tmp) })
return tmp
}
6 changes: 6 additions & 0 deletions test/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,12 @@ paths:
relativePath, _ := filepath.Rel(currentPath, path)
result := RunCli([]string{"myservice", "upload", "--file", relativePath}, context)

fmt.Println("Current: " + currentPath)
fmt.Println("Path: " + path)
fmt.Println("Relative: " + relativePath)
fmt.Println(result.StdOut)
fmt.Println(result.StdErr)

contentType := result.RequestHeader["content-type"]
if contentType != "application/octet-stream" {
t.Errorf("Content-Type is not application/octet-stream, got: %v", contentType)
Expand Down

0 comments on commit 0dbeedf

Please sign in to comment.