@@ -15,8 +15,31 @@ import (
1515func TestNew (t * testing.T ) {
1616 t .Parallel ()
1717
18+ _ , err := box .New (nil )
19+ require .Error (t , err )
20+ }
21+
22+ func TestMustNew (t * testing.T ) {
23+ t .Parallel ()
24+
1825 // Create a box instance with a nil connection. This should lead to a panic.
19- require .Panics (t , func () { box .New (nil ) })
26+ require .Panics (t , func () { box .MustNew (nil ) })
27+ }
28+
29+ func TestMocked_BoxNew (t * testing.T ) {
30+ t .Parallel ()
31+
32+ mock := test_helpers .NewMockDoer (t ,
33+ test_helpers .NewMockResponse (t , "valid" ),
34+ )
35+
36+ b , err := box .New (& mock )
37+ require .NoError (t , err )
38+ require .NotNil (t , b )
39+
40+ assert .Len (t , mock .Requests , 0 )
41+ b .Schema ().User ().Exists (box .NewInfoRequest ().Ctx (), "" )
42+ require .Len (t , mock .Requests , 1 )
2043}
2144
2245func TestMocked_BoxInfo (t * testing.T ) {
@@ -37,7 +60,7 @@ func TestMocked_BoxInfo(t *testing.T) {
3760 mock := test_helpers .NewMockDoer (t ,
3861 test_helpers .NewMockResponse (t , data ),
3962 )
40- b := box .New (& mock )
63+ b := box .MustNew (& mock )
4164
4265 info , err := b .Info ()
4366 require .NoError (t , err )
@@ -57,7 +80,7 @@ func TestMocked_BoxSchemaUserInfo(t *testing.T) {
5780 mock := test_helpers .NewMockDoer (t ,
5881 test_helpers .NewMockResponse (t , data ),
5982 )
60- b := box .New (& mock )
83+ b := box .MustNew (& mock )
6184
6285 privs , err := b .Schema ().User ().Info (context .Background (), "username" )
6386 require .NoError (t , err )
@@ -82,7 +105,7 @@ func TestMocked_BoxSessionSu(t *testing.T) {
82105 test_helpers .NewMockResponse (t , []interface {}{}),
83106 errors .New ("user not found or supplied credentials are invalid" ),
84107 )
85- b := box .New (& mock )
108+ b := box .MustNew (& mock )
86109
87110 err := b .Session ().Su (context .Background (), "admin" )
88111 require .NoError (t , err )
0 commit comments