Skip to content

Commit

Permalink
Merge pull request #3402 from apostasie/ci-fix-tests
Browse files Browse the repository at this point in the history
CI/test fixing
  • Loading branch information
AkihiroSuda authored Sep 4, 2024
2 parents 7910442 + 935ee8a commit 1b94da9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/nerdctl/container/container_run_security_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ func TestRunApparmor(t *testing.T) {
attrCurrentEnforceExpected := fmt.Sprintf("%s (enforce)\n", defaultProfile)
base.Cmd("run", "--rm", testutil.AlpineImage, "cat", attrCurrentPath).AssertOutExactly(attrCurrentEnforceExpected)
base.Cmd("run", "--rm", "--security-opt", "apparmor="+defaultProfile, testutil.AlpineImage, "cat", attrCurrentPath).AssertOutExactly(attrCurrentEnforceExpected)
base.Cmd("run", "--rm", "--security-opt", "apparmor=unconfined", testutil.AlpineImage, "cat", attrCurrentPath).AssertOutExactly("unconfined\n")
base.Cmd("run", "--rm", "--privileged", testutil.AlpineImage, "cat", attrCurrentPath).AssertOutExactly("unconfined\n")
base.Cmd("run", "--rm", "--security-opt", "apparmor=unconfined", testutil.AlpineImage, "cat", attrCurrentPath).AssertOutContains("unconfined")
base.Cmd("run", "--rm", "--privileged", testutil.AlpineImage, "cat", attrCurrentPath).AssertOutContains("unconfined")
}

// TestRunSeccompCapSysPtrace tests https://github.com/containerd/nerdctl/issues/976
Expand Down
28 changes: 20 additions & 8 deletions cmd/nerdctl/image/image_load_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,35 @@ import (
func TestLoadStdinFromPipe(t *testing.T) {
t.Parallel()
base := testutil.NewBase(t)

img := testutil.Identifier(t)
tmp := t.TempDir()
img := testutil.Identifier(t) + "image"
base.Cmd("pull", testutil.CommonImage).AssertOK()
base.Cmd("tag", testutil.CommonImage, img).AssertOK()
base.Cmd("save", img, "-o", filepath.Join(tmp, "common.tar")).AssertOK()
base.Cmd("rmi", "-f", img).AssertOK()
loadCmd := strings.Join(base.Cmd("load").Command, " ")
output := filepath.Join(tmp, "output")

setup := func() {
base.Cmd("pull", testutil.CommonImage).AssertOK()
base.Cmd("tag", testutil.CommonImage, img).AssertOK()
base.Cmd("save", img, "-o", filepath.Join(tmp, "common.tar")).AssertOK()
base.Cmd("rmi", "-f", img).AssertOK()
}

tearDown := func() {
base.Cmd("rmi", "-f", img).AssertOK()
}

t.Cleanup(tearDown)
tearDown()

setup()

loadCmd := strings.Join(base.Cmd("load").Command, " ")
combined, err := exec.Command("sh", "-euxc", fmt.Sprintf("`cat %s/common.tar | %s > %s`", tmp, loadCmd, output)).CombinedOutput()
assert.NilError(t, err, "failed with error %s and combined output is %s", err, string(combined))

fb, err := os.ReadFile(output)
assert.NilError(t, err)

assert.Assert(t, strings.Contains(string(fb), fmt.Sprintf("Loaded image: %s:latest", img)))
base.Cmd("images").AssertOutContains(testutil.ImageRepo(testutil.CommonImage))
base.Cmd("images").AssertOutContains(img)
}

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

0 comments on commit 1b94da9

Please sign in to comment.