Skip to content
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
2 changes: 1 addition & 1 deletion Vagrantfile.freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Vagrant.configure("2") do |config|
set -eux -o pipefail
daemon -o containerd.out containerd
sleep 3
/root/go/bin/nerdctl run --rm --net=none dougrabson/freebsd-minimal:13 echo "Nerdctl is up and running."
/root/go/bin/nerdctl run --rm --quiet --net=none dougrabson/freebsd-minimal:13 echo "Nerdctl is up and running."
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it is unrelated to the main topic here (separate commit though, for clarity).
Point is just to silence the noisy pull logs (freebsd CI is failing occasionally and I would like to be able to debug it a bit more easily).

SHELL
end

Expand Down
4 changes: 2 additions & 2 deletions cmd/nerdctl/builder/builder_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ CMD ["echo", "nerdctl-build-test-string"]`, testutil.CommonImage)
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rmi", "-f", data.Identifier())
},
Expected: test.Expects(-1, nil, nil),
Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil),
},
},
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestBuildFromStdin(t *testing.T) {
dockerfile := fmt.Sprintf(`FROM %s
CMD ["echo", "nerdctl-build-test-stdin"]`, testutil.CommonImage)
cmd := helpers.Command("build", "-t", data.Identifier(), "-f", "-", ".")
cmd.WithStdin(strings.NewReader(dockerfile))
cmd.Feed(strings.NewReader(dockerfile))
return cmd
},
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
Expand Down
2 changes: 1 addition & 1 deletion cmd/nerdctl/builder/builder_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CMD ["echo", "nerdctl-builder-debug-test-string"]`, testutil.CommonImage)
err := os.WriteFile(filepath.Join(buildCtx, "Dockerfile"), []byte(dockerfile), 0o600)
assert.NilError(helpers.T(), err)
cmd := helpers.Command("builder", "debug", buildCtx)
cmd.WithStdin(bytes.NewReader([]byte("c\n")))
cmd.Feed(bytes.NewReader([]byte("c\n")))
return cmd
},
Expected: test.Expects(0, nil, nil),
Expand Down
52 changes: 22 additions & 30 deletions cmd/nerdctl/container/container_attach_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package container

import (
"bytes"
"errors"
"os"
"io"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -56,11 +57,9 @@ func TestAttach(t *testing.T) {

testCase.Setup = func(data test.Data, helpers test.Helpers) {
cmd := helpers.Command("run", "--rm", "-it", "--name", data.Identifier(), testutil.CommonImage)
cmd.WithPseudoTTY(func(f *os.File) error {
// ctrl+p and ctrl+q (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
_, err := f.Write([]byte{16, 17})
return err
})
cmd.WithPseudoTTY()
// ctrl+p and ctrl+q (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
cmd.Feed(bytes.NewReader([]byte{16, 17}))

cmd.Run(&test.Expected{
ExitCode: 0,
Expand All @@ -74,15 +73,15 @@ func TestAttach(t *testing.T) {
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
// Run interactively and detach
cmd := helpers.Command("attach", data.Identifier())
cmd.WithPseudoTTY(func(f *os.File) error {
_, _ = f.WriteString("echo mark${NON}mark\n")

cmd.WithPseudoTTY()
cmd.Feed(strings.NewReader("echo mark${NON}mark\n"))
cmd.WithFeeder(func() io.Reader {
// Interestingly, and unlike with run, on attach, docker (like nerdctl) ALSO needs a pause so that the
// container can read stdin before we detach
time.Sleep(time.Second)
// ctrl+p and ctrl+q (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
_, err := f.Write([]byte{16, 17})

return err
return bytes.NewReader([]byte{16, 17})
})

return cmd
Expand Down Expand Up @@ -120,10 +119,8 @@ func TestAttachDetachKeys(t *testing.T) {

testCase.Setup = func(data test.Data, helpers test.Helpers) {
cmd := helpers.Command("run", "--rm", "-it", "--detach-keys=ctrl-q", "--name", data.Identifier(), testutil.CommonImage)
cmd.WithPseudoTTY(func(f *os.File) error {
_, err := f.Write([]byte{17})
return err
})
cmd.WithPseudoTTY()
cmd.Feed(bytes.NewReader([]byte{17}))

cmd.Run(&test.Expected{
ExitCode: 0,
Expand All @@ -137,15 +134,14 @@ func TestAttachDetachKeys(t *testing.T) {
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
// Run interactively and detach
cmd := helpers.Command("attach", "--detach-keys=ctrl-a,ctrl-b", data.Identifier())
cmd.WithPseudoTTY(func(f *os.File) error {
_, _ = f.WriteString("echo mark${NON}mark\n")
cmd.WithPseudoTTY()
cmd.Feed(strings.NewReader("echo mark${NON}mark\n"))
cmd.WithFeeder(func() io.Reader {
// Interestingly, and unlike with run, on attach, docker (like nerdctl) ALSO needs a pause so that the
// container can read stdin before we detach
time.Sleep(time.Second)
// ctrl+a and ctrl+b (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
_, err := f.Write([]byte{1, 2})

return err
// ctrl+p and ctrl+q (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
return bytes.NewReader([]byte{1, 2})
})

return cmd
Expand Down Expand Up @@ -179,11 +175,9 @@ func TestAttachForAutoRemovedContainer(t *testing.T) {

testCase.Setup = func(data test.Data, helpers test.Helpers) {
cmd := helpers.Command("run", "--rm", "-it", "--detach-keys=ctrl-a,ctrl-b", "--name", data.Identifier(), testutil.CommonImage)
cmd.WithPseudoTTY(func(f *os.File) error {
// ctrl+a and ctrl+b (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
_, err := f.Write([]byte{1, 2})
return err
})
cmd.WithPseudoTTY()
// ctrl+a and ctrl+b (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
cmd.Feed(bytes.NewReader([]byte{1, 2}))

cmd.Run(&test.Expected{
ExitCode: 0,
Expand All @@ -197,10 +191,8 @@ func TestAttachForAutoRemovedContainer(t *testing.T) {
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
// Run interactively and detach
cmd := helpers.Command("attach", data.Identifier())
cmd.WithPseudoTTY(func(f *os.File) error {
_, err := f.WriteString("echo mark${NON}mark\nexit 42\n")
return err
})
cmd.WithPseudoTTY()
cmd.Feed(strings.NewReader("echo mark${NON}mark\nexit 42\n"))

return cmd
}
Expand Down
19 changes: 10 additions & 9 deletions cmd/nerdctl/container/container_run_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ func TestRunSigProxy(t *testing.T) {
},

Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
// FIXME: os.Interrupt will likely not work on Windows
cmd := nerdtest.RunSigProxyContainer(os.Interrupt, true, nil, data, helpers)
err := cmd.Signal(os.Interrupt)
assert.NilError(helpers.T(), err)
Expand Down Expand Up @@ -417,7 +418,7 @@ func TestRunSigProxy(t *testing.T) {
return cmd
},

Expected: test.Expects(127, nil, expect.DoesNotContain(nerdtest.SignalCaught)),
Expected: test.Expects(expect.ExitCodeSignaled, nil, expect.DoesNotContain(nerdtest.SignalCaught)),
},
}

Expand Down Expand Up @@ -503,8 +504,9 @@ func TestRunWithDetachKeys(t *testing.T) {
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
// Run interactively and detach
cmd := helpers.Command("run", "-it", "--detach-keys=ctrl-a,ctrl-b", "--name", data.Identifier(), testutil.CommonImage)
cmd.WithPseudoTTY(func(f *os.File) error {
_, _ = f.WriteString("echo mark${NON}mark\n")
cmd.WithPseudoTTY()
cmd.Feed(strings.NewReader("echo mark${NON}mark\n"))
cmd.WithFeeder(func() io.Reader {
// Because of the way we proxy stdin, we have to wait here, otherwise we detach before
// the rest of the input ever reaches the container
// Note that this only concerns nerdctl, as docker seems to behave ok LOCALLY.
Expand All @@ -514,8 +516,7 @@ func TestRunWithDetachKeys(t *testing.T) {
nerdtest.EnsureContainerStarted(helpers, data.Identifier())
// }
// ctrl+a and ctrl+b (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
_, err := f.Write([]byte{1, 2})
return err
return bytes.NewReader([]byte{1, 2})
})

return cmd
Expand Down Expand Up @@ -571,8 +572,9 @@ func TestIssue3568(t *testing.T) {
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
// Run interactively and detach
cmd := helpers.Command("run", "--rm", "-it", "--detach-keys=ctrl-a,ctrl-b", "--name", data.Identifier(), testutil.CommonImage)
cmd.WithPseudoTTY(func(f *os.File) error {
_, _ = f.WriteString("echo mark${NON}mark\n")
cmd.WithPseudoTTY()
cmd.Feed(strings.NewReader("echo mark${NON}mark\n"))
cmd.WithFeeder(func() io.Reader {
// Because of the way we proxy stdin, we have to wait here, otherwise we detach before
// the rest of the input ever reaches the container
// Note that this only concerns nerdctl, as docker seems to behave ok LOCALLY.
Expand All @@ -582,8 +584,7 @@ func TestIssue3568(t *testing.T) {
nerdtest.EnsureContainerStarted(helpers, data.Identifier())
// }
// ctrl+a and ctrl+b (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
_, err := f.Write([]byte{1, 2})
return err
return bytes.NewReader([]byte{1, 2})
})

return cmd
Expand Down
15 changes: 7 additions & 8 deletions cmd/nerdctl/container/container_start_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package container

import (
"bytes"
"errors"
"os"
"io"
"strings"
"testing"

Expand All @@ -40,10 +41,8 @@ func TestStartDetachKeys(t *testing.T) {

testCase.Setup = func(data test.Data, helpers test.Helpers) {
cmd := helpers.Command("run", "-it", "--name", data.Identifier(), testutil.CommonImage)
cmd.WithPseudoTTY(func(f *os.File) error {
_, err := f.WriteString("exit\n")
return err
})
cmd.WithPseudoTTY()
cmd.Feed(strings.NewReader("exit\n"))
cmd.Run(&test.Expected{
ExitCode: 0,
})
Expand All @@ -60,10 +59,10 @@ func TestStartDetachKeys(t *testing.T) {
flags += "i"
}
cmd := helpers.Command("start", flags, "--detach-keys=ctrl-a,ctrl-b", data.Identifier())
cmd.WithPseudoTTY(func(f *os.File) error {
cmd.WithPseudoTTY()
cmd.WithFeeder(func() io.Reader {
// ctrl+a and ctrl+b (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
_, err := f.Write([]byte{1, 2})
return err
return bytes.NewReader([]byte{1, 2})
})

return cmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/nerdctl/image/image_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ RUN echo "actually creating a layer so that docker sets the createdAt time"
Description: "since=non-exists-image",
Require: nerdtest.NerdctlNeedsFixing("https://github.com/containerd/nerdctl/issues/3511"),
Command: test.Command("images", "--filter", "since=non-exists-image"),
Expected: test.Expects(-1, []error{errors.New("No such image: ")}, nil),
Expected: test.Expects(expect.ExitCodeGenericFail, []error{errors.New("No such image: ")}, nil),
},
{
Description: "before=non-exists-image",
Require: nerdtest.NerdctlNeedsFixing("https://github.com/containerd/nerdctl/issues/3511"),
Command: test.Command("images", "--filter", "before=non-exists-image"),
Expected: test.Expects(-1, []error{errors.New("No such image: ")}, nil),
Expected: test.Expects(expect.ExitCodeGenericFail, []error{errors.New("No such image: ")}, nil),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/nerdctl/image/image_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestLoadStdinFromPipe(t *testing.T) {
cmd := helpers.Command("load")
reader, err := os.Open(filepath.Join(data.TempDir(), "common.tar"))
assert.NilError(t, err, "failed to open common.tar")
cmd.WithStdin(reader)
cmd.Feed(reader)
return cmd
},
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
Expand Down
9 changes: 5 additions & 4 deletions cmd/nerdctl/ipfs/ipfs_compose_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ipfs
import (
"fmt"
"io"
"os"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -211,8 +212,9 @@ func TestIPFSCompBuild(t *testing.T) {
// Start a local ipfs backed registry
// FIXME: this is bad and likely to collide with other tests
ipfsServer = helpers.Command("ipfs", "registry", "serve", "--listen-registry", listenAddr)
// Once foregrounded, do not wait for it more than a second
ipfsServer.Background(1 * time.Second)
// This should not take longer than that
ipfsServer.WithTimeout(30 * time.Second)
ipfsServer.Background()
// Apparently necessary to let it start...
time.Sleep(time.Second)

Expand All @@ -237,9 +239,8 @@ COPY index.html /usr/share/nginx/html/index.html

testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
if ipfsServer != nil {
// Close the server once done
helpers.Anyhow("rmi", "-f", data.Get(mainImageCIDKey))
ipfsServer.Run(nil)
ipfsServer.Signal(os.Kill)
}
if comp != nil {
helpers.Anyhow("compose", "-f", comp.YAMLFullPath(), "down", "-v")
Expand Down
7 changes: 4 additions & 3 deletions cmd/nerdctl/ipfs/ipfs_registry_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ func TestIPFSNerdctlRegistry(t *testing.T) {

// Start a local ipfs backed registry
ipfsServer = helpers.Command("ipfs", "registry", "serve", "--listen-registry", listenAddr)
// Once foregrounded, do not wait for it more than a second
ipfsServer.Background(1 * time.Second)
// This should not take longer than that
ipfsServer.WithTimeout(30 * time.Second)
ipfsServer.Background()
// Apparently necessary to let it start...
time.Sleep(time.Second)
}

testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
if ipfsServer != nil {
// Close the server once done
ipfsServer.Run(nil)
ipfsServer.Signal(os.Kill)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/nerdctl/issues/main_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestIssue108(t *testing.T) {
{
Description: "-it --net=host",
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
cmd := helpers.Command("run", "-it", "--rm", "--net=host", testutil.CommonImage, "echo", "this was always working")
cmd := helpers.Command("run", "--quiet", "-it", "--rm", "--net=host", testutil.CommonImage, "echo", "this was always working")
cmd.WithPseudoTTY()
return cmd
},
Expand All @@ -48,7 +48,7 @@ func TestIssue108(t *testing.T) {
{
Description: "--net=host -it",
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
cmd := helpers.Command("run", "--rm", "--net=host", "-it", testutil.CommonImage, "echo", "this was not working due to issue #108")
cmd := helpers.Command("run", "--quiet", "--rm", "--net=host", "-it", testutil.CommonImage, "echo", "this was not working due to issue #108")
cmd.WithPseudoTTY()
return cmd
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/nerdctl/main_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestTest(t *testing.T) {
{
Description: "failure with multiple error testing",
Command: test.Command("-fail"),
Expected: test.Expects(-1, []error{errors.New("unknown"), errors.New("shorthand")}, nil),
Expected: test.Expects(expect.ExitCodeGenericFail, []error{errors.New("unknown"), errors.New("shorthand")}, nil),
},
{
Description: "success with exact output testing",
Expand Down
4 changes: 3 additions & 1 deletion cmd/nerdctl/system/system_events_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (

func testEventFilterExecutor(data test.Data, helpers test.Helpers) test.TestableCommand {
cmd := helpers.Command("events", "--filter", data.Get("filter"), "--format", "json")
cmd.Background(1 * time.Second)
// 3 seconds is too short on slow rig (EL8)
cmd.WithTimeout(10 * time.Second)
cmd.Background()
helpers.Ensure("run", "--rm", testutil.CommonImage)
return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/nerdctl/volume/volume_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestVolumeCreate(t *testing.T) {
helpers.Anyhow("volume", "rm", "-f", data.Identifier())
},
// NOTE: docker returns 125 on this
Expected: test.Expects(-1, []error{errdefs.ErrInvalidArgument}, nil),
Expected: test.Expects(expect.ExitCodeGenericFail, []error{errdefs.ErrInvalidArgument}, nil),
},
{
Description: "creating already existing volume should succeed",
Expand Down
1 change: 0 additions & 1 deletion mod/tigron/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ linters:
- github.com/creack/pty
- golang.org/x/sync
- golang.org/x/term
- gotest.tools/v3
- go.uber.org/goleak
staticcheck:
checks:
Expand Down
Loading