Skip to content

Commit

Permalink
Merge pull request #3566 from apostasie/part6
Browse files Browse the repository at this point in the history
Fix and enable CI unit testing for windows
  • Loading branch information
AkihiroSuda authored Oct 18, 2024
2 parents 388fe79 + ca76611 commit c05251d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,19 @@ jobs:
make lint-imports
test-unit:
runs-on: ubuntu-24.04
timeout-minutes: 20
timeout-minutes: 5
name: unit | ${{ matrix.goos }}
runs-on: "${{ matrix.os }}"
defaults:
run:
shell: bash
strategy:
matrix:
include:
- os: windows-2022
goos: windows
- os: ubuntu-24.04
goos: linux
steps:
- uses: actions/[email protected]
with:
Expand All @@ -51,6 +62,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: go test -v ./pkg/...

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

import (
"fmt"
"path/filepath"
"reflect"
"runtime"
"testing"

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

if runtime.GOOS == "windows" {
abspath, err := filepath.Abs("/tmp/oci-layout")
assert.NilError(t, err)
tests[1].expectedErr = fmt.Sprintf(
"open %s\\index.json: The system cannot find the path specified.",
abspath,
)
}

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

0 comments on commit c05251d

Please sign in to comment.