Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
kataLog = kataLog.WithField("container", containerID)
setExternalLoggers(kataLog)

if bundlePath == "" {
cwd, err := os.Getwd()
if err != nil {
return err
}

kataLog.WithField("directory", cwd).Debug("Defaulting bundle path to current directory")

bundlePath = cwd
}

// Checks the MUST and MUST NOT from OCI runtime specification
if bundlePath, err = validCreateParams(containerID, bundlePath); err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -564,6 +565,13 @@ func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
err = writeOCIConfigFile(spec, ociConfigFile)
assert.NoError(err)

err = create(testContainerID, "", testConsole, pidFilePath, false, runtimeConfig)
assert.Error(err, "bundle path not set")

re := regexp.MustCompile("config.json.*no such file or directory")
matches := re.FindAllStringSubmatch(err.Error(), -1)
assert.NotEmpty(matches)

for _, detach := range []bool{true, false} {
err := create(testContainerID, bundlePath, testConsole, pidFilePath, detach, runtimeConfig)
assert.NoError(err, "detached: %+v", detach)
Expand Down
44 changes: 38 additions & 6 deletions cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"testing"

vc "github.com/kata-containers/runtime/virtcontainers"
Expand Down Expand Up @@ -284,13 +285,44 @@ func TestRunContainerSuccessful(t *testing.T) {
testingImpl.DeleteContainerFunc = nil
}()

err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
type errorTestArgs struct {
bundlePath string

// regex string for text of error message
errorRE string

// If true, expect a cli.ExitError, else expect any other type
// of error.
expectExitError bool
}

args := []errorTestArgs{
{"", "config.json: no such file or directory", false},
{d.bundlePath, "", true},
}

// should return ExitError with the message and exit code
e, ok := err.(*cli.ExitError)
assert.True(ok, "error should be a cli.ExitError: %s", err)
assert.Empty(e.Error())
assert.NotZero(e.ExitCode())
for i, a := range args {
err = run(d.sandbox.ID(), a.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
assert.Errorf(err, "test args %d (%+v)", i, a)

if a.errorRE == "" {
assert.Empty(err.Error())
} else {
re := regexp.MustCompile(a.errorRE)
matches := re.FindAllStringSubmatch(err.Error(), -1)
assert.NotEmpty(matches)
}

e, ok := err.(*cli.ExitError)

if a.expectExitError {
// should return ExitError with the message and exit code
assert.Truef(ok, "test args %d (%+v): error should be a cli.ExitError: %s", i, a, err)
assert.NotZero(e.ExitCode())
} else {
assert.Falsef(ok, "test args %d (%+v): error should not be a cli.ExitError: %s", i, a, err)
}
}
}

func TestRunContainerDetachSuccessful(t *testing.T) {
Expand Down