unittests: Fixes unit tests for Windows (part 11)
Currently, there are some unit tests that are failing on Windows due to various reasons: - Cannot remove a directory if there's a file open in that directory. - Paths may have / or \ on Windows.
This commit is contained in:
		@@ -428,6 +428,8 @@ func hasPathPrefix(path, prefix string) bool {
 | 
				
			|||||||
	if prefix == "" || path == prefix {
 | 
						if prefix == "" || path == prefix {
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						path = filepath.Clean(path)
 | 
				
			||||||
 | 
						prefix = filepath.Clean(prefix)
 | 
				
			||||||
	if !strings.HasSuffix(path, string(filepath.Separator)) {
 | 
						if !strings.HasSuffix(path, string(filepath.Separator)) {
 | 
				
			||||||
		prefix += string(filepath.Separator)
 | 
							prefix += string(filepath.Separator)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	goruntime "runtime"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -121,10 +120,6 @@ func TestHasTestFiles(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPackageDir(t *testing.T) {
 | 
					func TestPackageDir(t *testing.T) {
 | 
				
			||||||
	if goruntime.GOOS == "windows" {
 | 
					 | 
				
			||||||
		// TODO: remove skip once the failing test has been fixed.
 | 
					 | 
				
			||||||
		t.Skip("Skip failing test on Windows.")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	cases := []struct {
 | 
						cases := []struct {
 | 
				
			||||||
		input  *packages.Package
 | 
							input  *packages.Package
 | 
				
			||||||
		expect string
 | 
							expect string
 | 
				
			||||||
@@ -134,13 +129,13 @@ func TestPackageDir(t *testing.T) {
 | 
				
			|||||||
			GoFiles:      []string{"/src/prj/file.go"},
 | 
								GoFiles:      []string{"/src/prj/file.go"},
 | 
				
			||||||
			IgnoredFiles: []string{"/otherdir/file.go"},
 | 
								IgnoredFiles: []string{"/otherdir/file.go"},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		expect: "/src/prj",
 | 
							expect: filepath.Clean("/src/prj"),
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		input: &packages.Package{
 | 
							input: &packages.Package{
 | 
				
			||||||
			PkgPath:      "example.com/foo/bar/qux",
 | 
								PkgPath:      "example.com/foo/bar/qux",
 | 
				
			||||||
			IgnoredFiles: []string{"/src/prj/file.go"},
 | 
								IgnoredFiles: []string{"/src/prj/file.go"},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		expect: "/src/prj",
 | 
							expect: filepath.Clean("/src/prj"),
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		input: &packages.Package{
 | 
							input: &packages.Package{
 | 
				
			||||||
			PkgPath: "example.com/foo/bar/qux",
 | 
								PkgPath: "example.com/foo/bar/qux",
 | 
				
			||||||
@@ -157,10 +152,6 @@ func TestPackageDir(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestHasPathPrefix(t *testing.T) {
 | 
					func TestHasPathPrefix(t *testing.T) {
 | 
				
			||||||
	if goruntime.GOOS == "windows" {
 | 
					 | 
				
			||||||
		// TODO: remove skip once the failing test has been fixed.
 | 
					 | 
				
			||||||
		t.Skip("Skip failing test on Windows.")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	cases := []struct {
 | 
						cases := []struct {
 | 
				
			||||||
		base   string
 | 
							base   string
 | 
				
			||||||
		pfx    string
 | 
							pfx    string
 | 
				
			||||||
@@ -228,10 +219,6 @@ func checkAllErrorStrings(t *testing.T, errs []error, expect []string) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestSimpleForward(t *testing.T) {
 | 
					func TestSimpleForward(t *testing.T) {
 | 
				
			||||||
	if goruntime.GOOS == "windows" {
 | 
					 | 
				
			||||||
		// TODO: remove skip once the failing test has been fixed.
 | 
					 | 
				
			||||||
		t.Skip("Skip failing test on Windows.")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	pkgs, err := loadPkgs("./testdata/simple-fwd/aaa")
 | 
						pkgs, err := loadPkgs("./testdata/simple-fwd/aaa")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("unexpected failure: %v", err)
 | 
							t.Fatalf("unexpected failure: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,6 @@ import (
 | 
				
			|||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	goruntime "runtime"
 | 
					 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/client-go/tools/clientcmd"
 | 
						"k8s.io/client-go/tools/clientcmd"
 | 
				
			||||||
@@ -203,10 +202,6 @@ func writeTestKubeconfig(t *testing.T, dir, name string, caCert *x509.Certificat
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestFileExists(t *testing.T) {
 | 
					func TestFileExists(t *testing.T) {
 | 
				
			||||||
	if goruntime.GOOS == "windows" {
 | 
					 | 
				
			||||||
		// TODO: remove skip once the failing test has been fixed.
 | 
					 | 
				
			||||||
		t.Skip("Skip failing test on Windows.")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	tmpdir, err := os.MkdirTemp("", "")
 | 
						tmpdir, err := os.MkdirTemp("", "")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Couldn't create tmpdir: %v", err)
 | 
							t.Fatalf("Couldn't create tmpdir: %v", err)
 | 
				
			||||||
@@ -221,6 +216,10 @@ func TestFileExists(t *testing.T) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Couldn't create tmpfile: %v", err)
 | 
							t.Fatalf("Couldn't create tmpfile: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if err := tmpfile.Close(); err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("Couldn't close tmpfile: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name     string
 | 
							name     string
 | 
				
			||||||
		filename string
 | 
							filename string
 | 
				
			||||||
@@ -308,10 +307,6 @@ func TestPKICertificateReadWriterExists(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestKubeConfigReadWriterExists(t *testing.T) {
 | 
					func TestKubeConfigReadWriterExists(t *testing.T) {
 | 
				
			||||||
	if goruntime.GOOS == "windows" {
 | 
					 | 
				
			||||||
		// TODO: remove skip once the failing test has been fixed.
 | 
					 | 
				
			||||||
		t.Skip("Skip failing test on Windows.")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	tmpdir, err := os.MkdirTemp("", "")
 | 
						tmpdir, err := os.MkdirTemp("", "")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Couldn't create tmpdir: %v", err)
 | 
							t.Fatalf("Couldn't create tmpdir: %v", err)
 | 
				
			||||||
@@ -326,6 +321,10 @@ func TestKubeConfigReadWriterExists(t *testing.T) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Couldn't create tmpfile: %v", err)
 | 
							t.Fatalf("Couldn't create tmpfile: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if err := tmpfile.Close(); err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("Couldn't close tmpfile: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name               string
 | 
							name               string
 | 
				
			||||||
		kubeConfigFilePath string
 | 
							kubeConfigFilePath string
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user