mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-04-09 06:54:06 +00:00
[no-relnote] Address stricter validation
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
47c208aab3
commit
043474bf04
@ -28,6 +28,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestSpec(t *testing.T) {
|
func TestSpec(t *testing.T) {
|
||||||
|
minimalSpec := &specs.Spec{
|
||||||
|
Kind: "nvidia.com/gpu",
|
||||||
|
Devices: []specs.Device{
|
||||||
|
{
|
||||||
|
Name: "one",
|
||||||
|
ContainerEdits: specs.ContainerEdits{
|
||||||
|
Env: []string{"DEVICE_FOO=bar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
options []Option
|
options []Option
|
||||||
@ -35,23 +47,17 @@ func TestSpec(t *testing.T) {
|
|||||||
transform transform.Transformer
|
transform transform.Transformer
|
||||||
expectedSpec string
|
expectedSpec string
|
||||||
}{
|
}{
|
||||||
{
|
|
||||||
description: "default options return empty spec",
|
|
||||||
expectedSpec: `---
|
|
||||||
cdiVersion: 0.3.0
|
|
||||||
containerEdits: {}
|
|
||||||
devices: null
|
|
||||||
kind: nvidia.com/gpu
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
description: "version is overridden",
|
description: "version is overridden",
|
||||||
options: []Option{WithVersion("0.5.0")},
|
options: []Option{WithVersion("0.8.0"), WithRawSpec(minimalSpec)},
|
||||||
expectedSpec: `---
|
expectedSpec: `---
|
||||||
cdiVersion: 0.5.0
|
cdiVersion: 0.8.0
|
||||||
containerEdits: {}
|
|
||||||
devices: null
|
|
||||||
kind: nvidia.com/gpu
|
kind: nvidia.com/gpu
|
||||||
|
devices:
|
||||||
|
- name: one
|
||||||
|
containerEdits:
|
||||||
|
env:
|
||||||
|
- DEVICE_FOO=bar
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -60,18 +66,24 @@ kind: nvidia.com/gpu
|
|||||||
&specs.Spec{
|
&specs.Spec{
|
||||||
Version: "0.5.0",
|
Version: "0.5.0",
|
||||||
Kind: "nvidia.com/gpu",
|
Kind: "nvidia.com/gpu",
|
||||||
ContainerEdits: specs.ContainerEdits{
|
Devices: []specs.Device{
|
||||||
Env: []string{"FOO=bar"},
|
{
|
||||||
|
Name: "one",
|
||||||
|
ContainerEdits: specs.ContainerEdits{
|
||||||
|
Env: []string{"DEVICE_FOO=bar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)},
|
)},
|
||||||
expectedSpec: `---
|
expectedSpec: `---
|
||||||
cdiVersion: 0.5.0
|
cdiVersion: 0.5.0
|
||||||
containerEdits:
|
|
||||||
env:
|
|
||||||
- FOO=bar
|
|
||||||
devices: null
|
|
||||||
kind: nvidia.com/gpu
|
kind: nvidia.com/gpu
|
||||||
|
devices:
|
||||||
|
- name: one
|
||||||
|
containerEdits:
|
||||||
|
env:
|
||||||
|
- DEVICE_FOO=bar
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -79,18 +91,24 @@ kind: nvidia.com/gpu
|
|||||||
options: []Option{WithRawSpec(
|
options: []Option{WithRawSpec(
|
||||||
&specs.Spec{
|
&specs.Spec{
|
||||||
Kind: "nvidia.com/gpu",
|
Kind: "nvidia.com/gpu",
|
||||||
ContainerEdits: specs.ContainerEdits{
|
Devices: []specs.Device{
|
||||||
Env: []string{"FOO=bar"},
|
{
|
||||||
|
Name: "one",
|
||||||
|
ContainerEdits: specs.ContainerEdits{
|
||||||
|
Env: []string{"DEVICE_FOO=bar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)},
|
)},
|
||||||
expectedSpec: `---
|
expectedSpec: `---
|
||||||
cdiVersion: 0.3.0
|
cdiVersion: 0.3.0
|
||||||
containerEdits:
|
|
||||||
env:
|
|
||||||
- FOO=bar
|
|
||||||
devices: null
|
|
||||||
kind: nvidia.com/gpu
|
kind: nvidia.com/gpu
|
||||||
|
devices:
|
||||||
|
- name: one
|
||||||
|
containerEdits:
|
||||||
|
env:
|
||||||
|
- DEVICE_FOO=bar
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -98,8 +116,15 @@ kind: nvidia.com/gpu
|
|||||||
options: []Option{WithRawSpec(
|
options: []Option{WithRawSpec(
|
||||||
&specs.Spec{
|
&specs.Spec{
|
||||||
Kind: "nvidia.com/gpu",
|
Kind: "nvidia.com/gpu",
|
||||||
|
Devices: []specs.Device{
|
||||||
|
{
|
||||||
|
Name: "one",
|
||||||
|
ContainerEdits: specs.ContainerEdits{
|
||||||
|
Env: []string{"DEVICE_FOO=bar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
ContainerEdits: specs.ContainerEdits{
|
ContainerEdits: specs.ContainerEdits{
|
||||||
Env: []string{"FOO=bar"},
|
|
||||||
DeviceNodes: []*specs.DeviceNode{
|
DeviceNodes: []*specs.DeviceNode{
|
||||||
{
|
{
|
||||||
HostPath: "/some/dev/dev0",
|
HostPath: "/some/dev/dev0",
|
||||||
@ -111,14 +136,16 @@ kind: nvidia.com/gpu
|
|||||||
)},
|
)},
|
||||||
expectedSpec: `---
|
expectedSpec: `---
|
||||||
cdiVersion: 0.5.0
|
cdiVersion: 0.5.0
|
||||||
|
kind: nvidia.com/gpu
|
||||||
|
devices:
|
||||||
|
- name: one
|
||||||
|
containerEdits:
|
||||||
|
env:
|
||||||
|
- DEVICE_FOO=bar
|
||||||
containerEdits:
|
containerEdits:
|
||||||
deviceNodes:
|
deviceNodes:
|
||||||
- hostPath: /some/dev/dev0
|
- path: /dev/dev0
|
||||||
path: /dev/dev0
|
hostPath: /some/dev/dev0
|
||||||
env:
|
|
||||||
- FOO=bar
|
|
||||||
devices: null
|
|
||||||
kind: nvidia.com/gpu
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -126,8 +153,15 @@ kind: nvidia.com/gpu
|
|||||||
options: []Option{WithRawSpec(
|
options: []Option{WithRawSpec(
|
||||||
&specs.Spec{
|
&specs.Spec{
|
||||||
Kind: "nvidia.com/gpu",
|
Kind: "nvidia.com/gpu",
|
||||||
|
Devices: []specs.Device{
|
||||||
|
{
|
||||||
|
Name: "one",
|
||||||
|
ContainerEdits: specs.ContainerEdits{
|
||||||
|
Env: []string{"DEVICE_FOO=bar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
ContainerEdits: specs.ContainerEdits{
|
ContainerEdits: specs.ContainerEdits{
|
||||||
Env: []string{"FOO=bar"},
|
|
||||||
DeviceNodes: []*specs.DeviceNode{
|
DeviceNodes: []*specs.DeviceNode{
|
||||||
{
|
{
|
||||||
HostPath: "/some/dev/dev0",
|
HostPath: "/some/dev/dev0",
|
||||||
@ -147,14 +181,16 @@ kind: nvidia.com/gpu
|
|||||||
),
|
),
|
||||||
expectedSpec: `---
|
expectedSpec: `---
|
||||||
cdiVersion: 0.5.0
|
cdiVersion: 0.5.0
|
||||||
|
kind: nvidia.com/gpu
|
||||||
|
devices:
|
||||||
|
- name: one
|
||||||
|
containerEdits:
|
||||||
|
env:
|
||||||
|
- DEVICE_FOO=bar
|
||||||
containerEdits:
|
containerEdits:
|
||||||
deviceNodes:
|
deviceNodes:
|
||||||
- hostPath: /dev/dev0
|
- path: /dev/dev0
|
||||||
path: /dev/dev0
|
hostPath: /dev/dev0
|
||||||
env:
|
|
||||||
- FOO=bar
|
|
||||||
devices: null
|
|
||||||
kind: nvidia.com/gpu
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user