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

Unit test on windows #2562

Merged
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ jobs:
after_success:
# submit coverage.txt to codecov.io
- bash <(curl -s https://codecov.io/bash)

# YAML alias, for settings shared across the tests on windows
- &windows-test
stage: Test
name: "Unit test on windows"
os:
- windows
init:
- git config --system core.longpaths true
go_import_path: github.com/openshift/odo
go: "1.13.1"
install:
- systeminfo.exe | grep '^OS'
- choco install make
- make goget-tools
script:
- export PATH="$PATH:$GOPATH/bin"
- make bin
- rm -r /tmp/*
Copy link
Member

Choose a reason for hiding this comment

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

There is no /tmp on windows. How is this working? Is there some kind of conversion to windows paths?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kadel In travis minimal gnu for windows is set as a default terminal for running scripts. minimal gnu provides the similar Linux file system on windows platform. As per the gnu environment the temp file will be generated in /tmp directory. For example

Screen Shot 2020-03-10 at 4 16 56 PM

Screen Shot 2020-03-10 at 4 12 23 PM

So its good practice to remove the temp files before running the actual test.

- make test
after_success: skip

# YAML alias, for settings shared across the tests on macOS
- &osx-test
Expand Down
2 changes: 2 additions & 0 deletions pkg/component/watch_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !windows,!osx
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Skipping watch test build on windows and macOS. It will be revised in #2570

Copy link
Member

Choose a reason for hiding this comment

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

Skipping watch test build on windows and macOS. It will be revised in #2570

It would be good to add this as a comment to all skipped files.


package component

import (
Expand Down
7 changes: 4 additions & 3 deletions pkg/debug/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package debug

import (
"encoding/json"
"os"
"reflect"
"testing"

"github.com/openshift/odo/pkg/occlient"
"github.com/openshift/odo/pkg/testingutil"
"github.com/openshift/odo/pkg/testingutil/filesystem"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"reflect"
"testing"
)

// fakeOdoDebugFileString creates a json string of a fake OdoDebugFile
Expand Down
3 changes: 2 additions & 1 deletion pkg/occlient/occlient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,8 @@ func isSubDir(baseDir, otherDir string) bool {
if cleanedBaseDir == cleanedOtherDir {
return true
}
matches, _ := filepath.Match(fmt.Sprintf("%s/*", cleanedBaseDir), cleanedOtherDir)
//matches, _ := filepath.Match(fmt.Sprintf("%s/*", cleanedBaseDir), cleanedOtherDir)
matches, _ := filepath.Match(filepath.Join(cleanedBaseDir, "*"), cleanedOtherDir)
return matches
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/odo/cli/service/ui/ui_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// +build !windows
Copy link
Contributor Author

Choose a reason for hiding this comment

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


package ui

import (
"reflect"
"testing"

"github.com/Netflix/go-expect"
beta1 "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
"github.com/openshift/odo/pkg/service"
"github.com/openshift/odo/pkg/testingutil"
"github.com/stretchr/testify/require"
"gopkg.in/AlecAivazis/survey.v1/core"
"gopkg.in/AlecAivazis/survey.v1/terminal"
"reflect"
"testing"
)

func init() {
Expand Down
5 changes: 4 additions & 1 deletion pkg/testingutil/survey_ui.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// +build !windows
Copy link
Contributor Author

@prietyc123 prietyc123 Feb 25, 2020

Choose a reason for hiding this comment

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

Skipping build. Refer : #2630 for more details and same issue will be tracked in the mentioned link.


package testingutil

import (
"bytes"
"testing"

"github.com/Netflix/go-expect"
"github.com/hinshun/vt10x"
"github.com/stretchr/testify/require"
"gopkg.in/AlecAivazis/survey.v1"
"gopkg.in/AlecAivazis/survey.v1/terminal"
"testing"
)

// This whole file copies the testing infrastructure from survey lib since it cannot be imported. This mixes elements from:
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"runtime"
"sort"
"strconv"
"testing"
Expand Down Expand Up @@ -806,6 +807,11 @@ func TestGetAbsGlobExps(t *testing.T) {
for _, tt := range tests {
t.Run(tt.testName, func(t *testing.T) {
resultExps := GetAbsGlobExps(tt.directoryName, tt.inputRelativeGlobExps)
if runtime.GOOS == "windows" {
for index, element := range resultExps {
resultExps[index] = filepath.ToSlash(element)
}
}

if !reflect.DeepEqual(resultExps, tt.expectedGlobExps) {
t.Errorf("expected %v, got %v", tt.expectedGlobExps, resultExps)
Expand Down Expand Up @@ -1115,6 +1121,11 @@ func TestRemoveRelativePathFromFiles(t *testing.T) {

// Run function RemoveRelativePathFromFiles
output, err := RemoveRelativePathFromFiles(tt.args.input, tt.args.path)
if runtime.GOOS == "windows" {
for index, element := range output {
output[index] = filepath.ToSlash(element)
}
}

// Check for error
if !tt.wantErr == (err != nil) {
Expand Down