Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,80 @@ func TestCheckLinux(t *testing.T) {
assert.Equal(t, c.expected, specerror.FindError(err, c.expected), fmt.Sprintf("failed CheckLinux: %v %d", err, c.expected))
}
}

func TestCheckPlatform(t *testing.T) {
cases := []struct {
val rspec.Spec
platform string
expected specerror.Code
}{
{
val: rspec.Spec{
Version: "1.0.0",
},
platform: "linux",
expected: specerror.NonError,
},
{
val: rspec.Spec{
Version: "1.0.0",
},
platform: "windows",
expected: specerror.PlatformSpecConfOnWindowsSet,
},
{
val: rspec.Spec{
Version: "1.0.0",
Windows: &rspec.Windows{
LayerFolders: []string{"C:\\Layers\\layer1"},
},
},
platform: "windows",
expected: specerror.NonError,
},
}
for _, c := range cases {
v := NewValidator(&c.val, ".", false, c.platform)
err := v.CheckPlatform()
assert.Equal(t, c.expected, specerror.FindError(err, c.expected), fmt.Sprintf("failed CheckPlatform: %v %d", err, c.expected))
}
}

func TestCheckHooks(t *testing.T) {
cases := []struct {
val rspec.Spec
expected specerror.Code
}{
{
val: rspec.Spec{
Version: "1.0.0",
Hooks: &rspec.Hooks{
Prestart: []rspec.Hook{
{
Path: "/usr/bin/fix-mounts",
},
},
},
},
expected: specerror.NonError,
},
{
val: rspec.Spec{
Version: "1.0.0",
Hooks: &rspec.Hooks{
Prestart: []rspec.Hook{
{
Path: "usr",
},
},
},
},
expected: specerror.PosixHooksPathAbs,
},
}
for _, c := range cases {
v := NewValidator(&c.val, ".", false, "linux")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a test to demonstrate that Hooks is ignored on Windows?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add it later because the corresponding verification code is not perfect yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add it later because the corresponding verification code is not perfect yet.

Ah right, it is blocked on #538.

err := v.CheckHooks()
assert.Equal(t, c.expected, specerror.FindError(err, c.expected), fmt.Sprintf("failed CheckHooks: %v %d", err, c.expected))
}
}