Skip to content

Commit a4e2b92

Browse files
Panic just for a method that panics
Co-authored-by: Oleg Jukovec <oleg.jukovec@gmail.com>
1 parent a085b48 commit a4e2b92

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

box/box_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import (
88
)
99

1010
func TestNew(t *testing.T) {
11+
// Create a box instance with a nil connection. This should lead to a panic later.
12+
b := box.New(nil)
13+
14+
// Ensure the box instance is not nil (which it shouldn't be), but this is not meaningful
15+
// since we will panic when we call the Info method with the nil connection.
16+
require.NotNil(t, b)
17+
1118
// We expect a panic because we are passing a nil connection (nil Doer) to the By function.
1219
// The library does not control this zone, and the nil connection would cause a runtime error
1320
// when we attempt to call methods (like Info) on it.
1421
// This test ensures that such an invalid state is correctly handled by causing a panic,
1522
// as it's outside the library's responsibility.
1623
require.Panics(t, func() {
17-
// Create a box instance with a nil connection. This should lead to a panic later.
18-
b := box.New(nil)
19-
20-
// Ensure the box instance is not nil (which it shouldn't be), but this is not meaningful
21-
// since we will panic when we call the Info method with the nil connection.
22-
require.NotNil(t, b)
23-
2424
// Calling Info on a box with a nil connection will result in a panic, since the underlying
2525
// connection (Doer) cannot perform the requested action (it's nil).
2626
_, _ = b.Info()

0 commit comments

Comments
 (0)