refactor: Move from testify to be #130
No reviewers
Labels
No labels
breaking-change
bug
dependencies
duplicate
enhancement
go
good first issue
help wanted
invalid
investigation
proposal
proposal-accepted
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nemith/netconf!130
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "brb/push-svnllmppytku"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
testify has a lot of indirect dependencies. Be has zero.
Pull request overview
This PR refactors the test suite from testify to the
betesting library to reduce indirect dependencies. The migration replaces testify's assertion functions with their be equivalents across all test files, and updates go.mod/go.sum to remove testify and its dependencies.testify/assertandtestify/requiretogithub.com/carlmjohnson/beerrorsandstringspackages where needed for manual error checkingReviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@ -98,13 +97,13 @@ func TestWithCapability(t *testing.T) {Using
be.Equalfor comparingfalsewith a boolean result is correct, but it would be more idiomatic to usebe.False(t, session.ClientCaps().Has(CapNetConf10))which better expresses the intent of the assertion.@ -209,2 +206,4 @@be.Nonzero(t, err)be.Zero(t, session)// Transport should be closed on errorThe assertion has changed semantics. Previously,
assert.Equal(t, handler, session.notifHandler)checked that the handler is the exact same instance. Now,be.Nonzero(t, session.notifHandler)only checks that the handler is not nil, which is a weaker assertion. Consider keeping the original equality check withbe.Equal(t, handler, session.notifHandler)to maintain test coverage.@ -254,29 +253,29 @@ func TestPrepareDoesNotMutate(t *testing.T) {prepared := session.Prepare(rpc)The assertion has changed semantics. Previously,
assert.Equal(t, handler, session.notifHandler)checked that the handler is the exact same instance. Now,be.Nonzero(t, session.notifHandler)only checks that the handler is not nil, which is a weaker assertion. Consider keeping the original equality check withbe.Equal(t, handler, session.notifHandler)to maintain test coverage.@ -269,4 +268,4 @@rpc := NewRPC("test-op")ctx := context.Background()msg, err := session.Do(ctx, rpc)The assertion semantics have changed.
assert.NotNil(t, session.reqs)checks if the field is not nil, whilebe.Equal(t, 0, len(session.reqs))checks if it's an empty map. These are different assertions - the former tests initialization, the latter tests emptiness. Usebe.Nonzero(t, session.reqs)to maintain the original assertion semantics.@ -883,12 +882,12 @@ func TestHandshakeNoUpgradeWhenServerLacks11(t *testing.T) {ut := &upgradableTransport{Transport: tt}Using
be.Equalfor comparingfalsewith a boolean result is correct, but it would be more idiomatic to usebe.False(t, ut.upgraded)which better expresses the intent of the assertion.@ -221,8 +223,8 @@ func TestTransport_DialContextCancel(t *testing.T) {start := time.Now()The duration comparison logic is incorrect.
time.Since(start).Abs()returns a duration that's always positive, but the check should verify that the elapsed time is less than 200ms. The current code uses.Abs()on a duration, which is not correct. Usetime.Since(start) <= 200*time.Millisecondinstead.@ -163,8 +163,8 @@ func TestTransport_DialContextCancel(t *testing.T) {start := time.Now()The duration comparison logic is incorrect.
time.Since(start).Abs()returns a duration that's always positive, but the check should verify that the elapsed time is less than 200ms. The current code uses.Abs()on a duration, which is not correct. Usetime.Since(start) <= 200*time.Millisecondinstead.Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The test assertion has been weakened. The original
assert.Equal(t, got, tc.msg)compared the entire Hello struct for equality, but now only the SessionID and the length of Capabilities are checked. This means that if the Capabilities slice contains different values (but the same length), or if XMLName differs, the test will pass when it should fail. The complete struct comparison should be preserved.The test assertion has been weakened. The original
assert.Equal(t, tc.want, got)compared the entire RPCReply struct for equality, but now only the MessageID and the length of RPCErrors are checked. This means that if the RPCErrors slice contains different values (but the same length), or if XMLName differs, the test will pass when it should fail. The complete struct comparison should be preserved.@ -281,3 +283,3 @@err = w.Close()assert.NoError(t, err)be.NilErr(t, err)The assertion logic has been changed to check both conditions redundantly. The check
err != nil && strings.Contains(err.Error(), "unable to authenticate")is unnecessarily verbose. Ifbe.Inis the appropriate replacement forassert.ErrorContains, it should be used directly. However, the pattern suggestsbe.Inexpects the substring first and the string second, so this should be simplified to justbe.In(t, "unable to authenticate", err.Error())after first checking that err is not nil withbe.Nonzero(t, err)on line 191.@ -287,2 +288,3 @@be.NilErr(t, err)require.NoError(t, srv.Wait(t))be.NilErr(t, srv.Wait(t))The assertion logic has been changed to check both conditions redundantly. The check
err != nil && strings.Contains(err.Error(), "no auth passed yet")is unnecessarily verbose. Sincebe.Nonzero(t, err)was not called before this assertion to verify err is not nil, this could panic if err is nil. This should be split into two separate assertions: first check that err is not nil, then check the error message content.