Skip to content

Commit 6bce762

Browse files
committed
Fix failing tests on Darwin
Signed-off-by: Evan Lezar <[email protected]>
1 parent 4149a8a commit 6bce762

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

pkg/cdi/cache_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"path/filepath"
24+
"runtime"
2425
"strconv"
2526
"strings"
2627
"sync"
@@ -225,6 +226,9 @@ devices:
225226
}
226227

227228
func TestRefreshCache(t *testing.T) {
229+
if runtime.GOOS == "darwin" {
230+
t.Skip("skipping on darwin")
231+
}
228232
type specDirs struct {
229233
etc map[string]string
230234
run map[string]string

pkg/cdi/cache_test_darwin.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build darwin
2+
// +build darwin
3+
4+
/*
5+
Copyright © 2021 The CDI Authors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package cdi
21+
22+
import "syscall"
23+
24+
func osSync() {
25+
_ = syscall.Sync()
26+
}

pkg/cdi/cache_test_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build !windows && !darwin
2+
// +build !windows,!darwin
33

44
/*
55
Copyright © 2021 The CDI Authors

pkg/cdi/container-edits_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cdi
1818

1919
import (
20+
"runtime"
2021
"testing"
2122

2223
oci "github.com/opencontainers/runtime-spec/specs-go"
@@ -303,6 +304,13 @@ func TestValidateContainerEdits(t *testing.T) {
303304
}
304305

305306
func TestApplyContainerEdits(t *testing.T) {
307+
nullDeviceMajor := int64(1)
308+
nullDeviceMinor := int64(3)
309+
if runtime.GOOS == "darwin" {
310+
nullDeviceMajor = 3
311+
nullDeviceMinor = 2
312+
}
313+
306314
type testCase struct {
307315
name string
308316
spec *oci.Spec
@@ -346,17 +354,17 @@ func TestApplyContainerEdits(t *testing.T) {
346354
{
347355
Path: "/dev/null",
348356
Type: "c",
349-
Major: 1,
350-
Minor: 3,
357+
Major: nullDeviceMajor,
358+
Minor: nullDeviceMinor,
351359
},
352360
},
353361
Resources: &oci.LinuxResources{
354362
Devices: []oci.LinuxDeviceCgroup{
355363
{
356364
Allow: true,
357365
Type: "c",
358-
Major: int64ptr(1),
359-
Minor: int64ptr(3),
366+
Major: &nullDeviceMajor,
367+
Minor: &nullDeviceMinor,
360368
Access: "rwm",
361369
},
362370
},
@@ -389,17 +397,17 @@ func TestApplyContainerEdits(t *testing.T) {
389397
{
390398
Path: "/dev/null",
391399
Type: "c",
392-
Major: 1,
393-
Minor: 3,
400+
Major: nullDeviceMajor,
401+
Minor: nullDeviceMinor,
394402
},
395403
},
396404
Resources: &oci.LinuxResources{
397405
Devices: []oci.LinuxDeviceCgroup{
398406
{
399407
Allow: true,
400408
Type: "c",
401-
Major: int64ptr(1),
402-
Minor: int64ptr(3),
409+
Major: &nullDeviceMajor,
410+
Minor: &nullDeviceMinor,
403411
Access: "rwm",
404412
},
405413
},

pkg/cdi/default-cache_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cdi
1919
import (
2020
"fmt"
2121
"path/filepath"
22+
"runtime"
2223
"testing"
2324
"time"
2425

@@ -129,6 +130,9 @@ devices:
129130
}
130131

131132
func TestDefaultCacheRefresh(t *testing.T) {
133+
if runtime.GOOS == "darwin" {
134+
t.Skip("skipping on darwin")
135+
}
132136
type specDirs struct {
133137
etc map[string]string
134138
run map[string]string

0 commit comments

Comments
 (0)