Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolation strings, should match user input #3033

Merged
merged 1 commit into from Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions define/isolation.go
Expand Up @@ -21,14 +21,12 @@ const (
// String converts a Isolation into a string.
func (i Isolation) String() string {
switch i {
case IsolationDefault:
return "IsolationDefault"
case IsolationOCI:
return "IsolationOCI"
case IsolationDefault, IsolationOCI:
return "oci"
case IsolationChroot:
return "IsolationChroot"
return "chroot"
case IsolationOCIRootless:
return "IsolationOCIRootless"
return "rootless"
}
return fmt.Sprintf("unrecognized isolation type %d", i)
}
2 changes: 1 addition & 1 deletion pkg/parse/parse.go
Expand Up @@ -959,7 +959,7 @@ func defaultIsolation() (define.Isolation, error) {
func IsolationOption(isolation string) (define.Isolation, error) {
if isolation != "" {
switch strings.ToLower(isolation) {
case "oci":
case "oci", "default":
Copy link
Member

Choose a reason for hiding this comment

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

based on your changes above, is "default" possible?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder the same, but otherwise LGTM.

return define.IsolationOCI, nil
case "rootless":
return define.IsolationOCIRootless, nil
Expand Down
29 changes: 29 additions & 0 deletions pkg/parse/parse_test.go
@@ -1,6 +1,7 @@
package parse

import (
"fmt"
"runtime"
"testing"

Expand Down Expand Up @@ -93,3 +94,31 @@ func TestDeviceFromPath(t *testing.T) {
_, err = DeviceFromPath("/etc/passwd")
assert.Error(t, err)
}

func TestIsolation(t *testing.T) {
def, err := defaultIsolation()
if err != nil {
assert.Error(t, err)
}

isolations := []string{"", "default", "oci", "chroot", "rootless"}
for _, i := range isolations {
isolation, err := IsolationOption(i)
if err != nil {
assert.Error(t, fmt.Errorf("isolation %q not supported", i))
}
var expected string
switch i {
case "":
expected = def.String()
case "default":
expected = "oci"
default:
expected = i
}

if isolation.String() != expected {
assert.Error(t, fmt.Errorf("isolation %q not equal to user input %q", isolation.String(), expected))
}
}
}