Skip to content

[WIP] [CI] new command implementation for tests #4040

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

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
jobs:
go:
timeout-minutes: 5
name: "go | ${{ matrix.goos }} | ${{ matrix.canary }}"
name: "${{ matrix.goos }} | ${{ matrix.canary }}"
runs-on: "${{ matrix.os }}"
defaults:
run:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Set GO env
run: |
# If canary is specified, get the latest available golang pre-release instead of the major version
if [ "$canary" != "" ]; then
if [ "${{ matrix.canary }}" != "" ]; then
. ./hack/build-integration-canary.sh
canary::golang::latest
fi
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/tigron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: tigron

on:
push:
branches:
- main
- 'release/**'
pull_request:
paths: 'mod/tigron/**'

env:
GO_VERSION: 1.24.x
GOTOOLCHAIN: local

jobs:
lint:
timeout-minutes: 10
name: "${{ matrix.goos }} ${{ matrix.os }} | go ${{ matrix.canary }}"
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
matrix:
include:
- os: ubuntu-24.04
- os: macos-15
- os: windows-2022
- os: ubuntu-24.04
goos: freebsd
- os: ubuntu-24.04
canary: go-canary
steps:
- name: "Checkout project"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 100
- name: "Set GO env"
run: |
# If canary is specified, get the latest available golang pre-release instead of the major version
if [ "${{ matrix.canary }}" != "" ]; then
. ./hack/build-integration-canary.sh
canary::golang::latest
fi
- name: "Install go"
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: "Install tools"
run: |
cd mod/tigron
echo "::group:: make install-dev-tools"
make install-dev-tools
if [ "$RUNNER_OS" == macOS ]; then
brew install yamllint shellcheck
fi
echo "::endgroup::"
- name: "lint"
env:
NO_COLOR: true
run: |
if [ "$RUNNER_OS" != "Linux" ] || [ "${{ matrix.goos }}" != "" ]; then
echo "It is not necessary to run the linter on this platform (${{ env.RUNNER_OS }} ${{ matrix.goos }})"
exit
fi

echo "::group:: lint"
cd mod/tigron
export LINT_COMMIT_RANGE="$(jq -r '.after + "..HEAD"' ${GITHUB_EVENT_PATH})"
make lint
echo "::endgroup::"
- name: "test-unit"
run: |
echo "::group:: unit test"
cd mod/tigron
make test-unit
echo "::endgroup::"
- name: "test-unit-race"
run: |
echo "::group:: race test"
cd mod/tigron
make test-unit-race
echo "::endgroup::"
- name: "test-unit-bench"
run: |
echo "::group:: bench"
cd mod/tigron
make test-unit-bench
echo "::endgroup::"
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
1 change: 1 addition & 0 deletions cmd/nerdctl/container/container_inspect_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/containerd/nerdctl/mod/tigron/expect"
"github.com/containerd/nerdctl/mod/tigron/test"

"github.com/containerd/nerdctl/v2/pkg/infoutil"
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
"github.com/containerd/nerdctl/v2/pkg/labels"
Expand Down
3 changes: 2 additions & 1 deletion cmd/nerdctl/container/container_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"

"github.com/spf13/cobra"
"golang.org/x/term"

"github.com/containerd/console"
"github.com/containerd/log"
Expand Down Expand Up @@ -407,7 +408,7 @@ func runAction(cmd *cobra.Command, args []string) error {
return err
}
defer con.Reset()
if err := con.SetRaw(); err != nil {
if _, err := term.MakeRaw(int(con.Fd())); err != nil {
return err
}
}
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
Loading