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

internal: use sentinel error in TestVerifierErrorWrapping #1539

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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
19 changes: 6 additions & 13 deletions internal/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"testing"

"github.com/go-quicktest/qt"

"github.com/cilium/ebpf/internal/unix"
)

func TestVerifierErrorWhitespace(t *testing.T) {
Expand All @@ -34,18 +32,13 @@ func TestVerifierErrorWhitespace(t *testing.T) {
}

func TestVerifierErrorWrapping(t *testing.T) {
ve := ErrorWithLog("frob", unix.ENOENT, nil)
qt.Assert(t, qt.ErrorIs(ve, unix.ENOENT), qt.Commentf("should wrap provided error"))

ve = ErrorWithLog("frob", unix.EINVAL, nil)
qt.Assert(t, qt.ErrorIs(ve, unix.EINVAL), qt.Commentf("should wrap provided error"))
sentinel := errors.New("bad")

ve = ErrorWithLog("frob", unix.EINVAL, []byte("foo"))
qt.Assert(t, qt.ErrorIs(ve, unix.EINVAL), qt.Commentf("should wrap provided error"))
qt.Assert(t, qt.StringContains(ve.Error(), "foo"), qt.Commentf("verifier log should appear in error string"))
ve := ErrorWithLog("frob", sentinel, nil)
qt.Assert(t, qt.ErrorIs(ve, sentinel), qt.Commentf("should wrap provided error"))

ve = ErrorWithLog("frob", unix.ENOSPC, []byte("foo"))
qt.Assert(t, qt.ErrorIs(ve, unix.ENOSPC), qt.Commentf("should wrap provided error"))
ve = ErrorWithLog("frob", sentinel, []byte("foo"))
qt.Assert(t, qt.ErrorIs(ve, sentinel), qt.Commentf("should wrap provided error"))
qt.Assert(t, qt.StringContains(ve.Error(), "foo"), qt.Commentf("verifier log should appear in error string"))
}

Expand Down Expand Up @@ -81,5 +74,5 @@ func readErrorFromFile(tb testing.TB, file string) *VerifierError {
tb.Fatal("Read file:", err)
}

return ErrorWithLog("file", unix.EINVAL, contents)
return ErrorWithLog("file", errors.New("error"), contents)
}
Loading