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

[Tigron]: mocks + debugging output enhancements #4076

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 18 additions & 6 deletions mod/tigron/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@ issues:
linters:
default: all
disable:
- cyclop
- exhaustruct
- funlen
- godox
- nonamedreturns
# These are the linters that we know we do not want
- cyclop # provided by revive
- exhaustruct # does not serve much of a purpose
- funlen # provided by revive
- gocognit # provided by revive
- goconst # provided by revive
- godox # not helpful unless we could downgrade it to warning / info
- ginkgolinter # no ginkgo
- gomodguard # we use depguard instead
- ireturn # too annoying with not enough value
- lll # provided by golines
- nonamedreturns # named returns are occasionally useful
- prealloc # premature optimization
- promlinter # no prometheus
- sloglint # no slog
- testifylint # no testify
- zerologlint # no zerolog
settings:
depguard:
rules:
Expand Down Expand Up @@ -51,7 +63,7 @@ formatters:
gofumpt:
extra-rules: true
golines:
max-len: 100
max-len: 120
tab-len: 4
shorten-comments: true
enable:
Expand Down
42 changes: 9 additions & 33 deletions mod/tigron/expect/comparators.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
limitations under the License.
*/

//revive:disable:package-comments // annoying false positive behavior
//nolint:thelper // FIXME: remove when we move to tig.T
package expect

import (
"encoding/hex"
"fmt"
"regexp"
"strings"
"testing"

"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
Expand All @@ -29,7 +28,6 @@ import (

// All can be used as a parameter for expected.Output to group a set of comparators.
func All(comparators ...test.Comparator) test.Comparator {
//nolint:thelper
return func(stdout, info string, t *testing.T) {
t.Helper()

Expand All @@ -39,57 +37,35 @@ func All(comparators ...test.Comparator) test.Comparator {
}
}

// Contains can be used as a parameter for expected.Output and ensures a comparison string
// is found contained in the output.
// Contains can be used as a parameter for expected.Output and ensures a comparison string is found contained in the
// output.
func Contains(compare string) test.Comparator {
//nolint:thelper
return func(stdout, info string, t *testing.T) {
t.Helper()
assertive.Check(t, strings.Contains(stdout, compare),
fmt.Sprintf("Output does not contain: %q", compare),
info)
assertive.Contains(assertive.WithFailLater(t), stdout, compare, info)
}
}

// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in
// the output.
// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output.
func DoesNotContain(compare string) test.Comparator {
//nolint:thelper
return func(stdout, info string, t *testing.T) {
t.Helper()
assertive.Check(t, !strings.Contains(stdout, compare),
fmt.Sprintf("Output should not contain: %q", compare), info)
assertive.DoesNotContain(assertive.WithFailLater(t), stdout, compare, info)
}
}

// Equals is to be used for expected.Output to ensure it is exactly the output.
func Equals(compare string) test.Comparator {
//nolint:thelper
return func(stdout, info string, t *testing.T) {
t.Helper()

hexdump := hex.Dump([]byte(stdout))
assertive.Check(
t,
compare == stdout,
fmt.Sprintf("Output is not equal to: %q", compare),
"\n"+hexdump,
info,
)
assertive.IsEqual(assertive.WithFailLater(t), stdout, compare, info)
}
}

// Match is to be used for expected.Output to ensure we match a regexp.
// Provisional - expected use, but have not seen it so far.
func Match(reg *regexp.Regexp) test.Comparator {
//nolint:thelper
return func(stdout, info string, t *testing.T) {
t.Helper()
assertive.Check(
t,
reg.MatchString(stdout),
fmt.Sprintf("Output does not match: %q", reg.String()),
info,
)
assertive.Match(assertive.WithFailLater(t), stdout, reg, info)
}
}
Loading