Skip to content

Commit

Permalink
Enable unit tests for windows
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Oct 16, 2024
1 parent 1768c95 commit 4d4e613
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 5 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ jobs:
timeout-minutes: 5
name: unit | ${{ matrix.goos }}
runs-on: "${{ matrix.os }}"
defaults:
run:
shell: bash
strategy:
matrix:
include:
# FIXME: currently disabled as a lot more work is required to make these tests pass on windows
# - os: windows-2022
# goos: windows
- os: windows-2022
goos: windows
- os: ubuntu-24.04
goos: linux
steps:
Expand All @@ -39,6 +42,17 @@ jobs:
go-version: ${{ env.GO_VERSION }}
check-latest: true
cache: true
- if: ${{ matrix.goos=='windows' }}
uses: actions/[email protected]
with:
repository: containerd/containerd
ref: v1.7.23
path: containerd
fetch-depth: 1
- if: ${{ matrix.goos=='windows' }}
name: "Set up CNI"
working-directory: containerd
run: GOPATH=$(go env GOPATH) script/setup/install-cni-windows
- name: "Run unit tests"
run: make test-unit

Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/builder/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package builder

import (
"reflect"
"runtime"
"testing"

specs "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -213,6 +214,10 @@ func TestParseBuildctlArgsForOCILayout(t *testing.T) {
},
}

if runtime.GOOS == "windows" {
tests[1].expectedErr = "open D:\\tmp\\oci-layout\\index.json: The system cannot find the path specified."
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
args, err := parseBuildContextFromOCILayout(test.ociLayoutName, test.ociLayoutPath)
Expand Down
6 changes: 6 additions & 0 deletions pkg/composer/serviceparser/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package serviceparser

import (
"runtime"
"testing"

"gotest.tools/v3/assert"
Expand All @@ -30,6 +31,11 @@ func lastOf(ss []string) string {

func TestParseBuild(t *testing.T) {
t.Parallel()

if runtime.GOOS == "windows" {
t.Skip("test is not compatible with windows")
}

const dockerComposeYAML = `
services:
foo:
Expand Down
13 changes: 13 additions & 0 deletions pkg/composer/serviceparser/serviceparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"testing"

Expand Down Expand Up @@ -79,6 +80,11 @@ var in = strutil.InStringSlice

func TestParse(t *testing.T) {
t.Parallel()

if runtime.GOOS == "windows" {
t.Skip("test is not compatible with windows")
}

const dockerComposeYAML = `
version: '3.1'
Expand Down Expand Up @@ -333,6 +339,10 @@ services:

func TestParseRelative(t *testing.T) {
t.Parallel()

if runtime.GOOS == "windows" {
t.Skip("test is not compatible with windows")
}
const dockerComposeYAML = `
services:
foo:
Expand Down Expand Up @@ -408,6 +418,9 @@ services:

func TestParseConfigs(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("test is not compatible with windows")
}
const dockerComposeYAML = `
services:
foo:
Expand Down
4 changes: 4 additions & 0 deletions pkg/imgutil/dockerconfigresolver/credentialsstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func TestBrokenCredentialsStore(t *testing.T) {
// Anyhow, this test is about extreme cases & conditions (filesystem errors wrt credentials loading).
t.Skip("skipping broken credential store tests for freebsd")
}
if runtime.GOOS == "windows" {
// Same as above
t.Skip("test is not compatible with windows")
}

testCases := []struct {
description string
Expand Down
2 changes: 1 addition & 1 deletion pkg/inspecttypes/dockercompat/dockercompat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestContainerFromNative(t *testing.T) {
expected: &Container{
Created: "0001-01-01T00:00:00Z",
Platform: runtime.GOOS,
ResolvConfPath: tempStateDir + "/resolv.conf",
ResolvConfPath: filepath.Join(tempStateDir, "resolv.conf"),
State: &ContainerState{
Status: "running",
Running: true,
Expand Down
4 changes: 4 additions & 0 deletions pkg/logging/cri_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"testing"
"time"
)
Expand Down Expand Up @@ -234,6 +235,9 @@ func TestReadLogsLimitsWithTimestamps(t *testing.T) {

func TestReadRotatedLog(t *testing.T) {
tmpDir := t.TempDir()
if runtime.GOOS == "windows" {
t.Skip("windows implementation does not seem to work right now and should be fixed: https://github.com/containerd/nerdctl/issues/3554")
}
file, err := os.CreateTemp(tmpDir, "logfile")
if err != nil {
t.Errorf("unable to create temp file, error: %s", err.Error())
Expand Down
4 changes: 4 additions & 0 deletions pkg/logging/json_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
"time"
)

func TestReadRotatedJSONLog(t *testing.T) {
tmpDir := t.TempDir()
if runtime.GOOS == "windows" {
t.Skip("windows implementation does not seem to work right now and should be fixed: https://github.com/containerd/nerdctl/issues/3554")
}
file, err := os.CreateTemp(tmpDir, "logfile")
if err != nil {
t.Errorf("unable to create temp file, error: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/mountutil/mountutil_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestParseVolumeOptions(t *testing.T) {
vType: "bind",
src: "dummy",
optsRaw: "rw",
wants: []string{},
wants: nil,
},
{
vType: "volume",
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/filestore_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// See https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
// https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names
var (
disallowedKeywords = regexp.MustCompile(`(?i)^(con|prn|nul|aux|com[1-9¹²³]|lpt[1-9¹²³])([.].*)?`)
disallowedKeywords = regexp.MustCompile(`(?i)^(con|prn|nul|aux|com[1-9¹²³]|lpt[1-9¹²³])([.].*)?$`)
reservedCharacters = regexp.MustCompile(`[\x{0}-\x{1f}<>:"/\\|?*]`)
)

Expand Down

0 comments on commit 4d4e613

Please sign in to comment.