@@ -2844,17 +2844,28 @@ type CommonTestUtils struct {
28442844 }
28452845}
28462846
2847- // newCommonTestUtils creates a connection to each node (given that the nodes list is not empty)
2848- // and puts these connections in a cache for reuse. The caller should remember to close all connections
2849- // once done with them to prevent any goroutine leaks (CloseConnections).
2847+ type commonTestOption func (* CommonTestUtils )
2848+
2849+ func withMock (mock bool ) commonTestOption {
2850+ return func (c * CommonTestUtils ) {
2851+ c .mock = mock
2852+ }
2853+ }
2854+
2855+ func withOnlineRestore (or bool ) commonTestOption {
2856+ return func (c * CommonTestUtils ) {
2857+ c .onlineRestore = or
2858+ }
2859+ }
2860+
2861+ // Change the function signature
28502862func newCommonTestUtils (
28512863 ctx context.Context ,
28522864 t test.Test ,
28532865 c cluster.Cluster ,
28542866 connectFunc func (int ) (* gosql.DB , error ),
28552867 nodes option.NodeListOption ,
2856- mock bool ,
2857- onlineRestore bool ,
2868+ opts ... commonTestOption ,
28582869) (* CommonTestUtils , error ) {
28592870 cc := make ([]* gosql.DB , len (nodes ))
28602871 for _ , node := range nodes {
@@ -2870,13 +2881,16 @@ func newCommonTestUtils(
28702881 }
28712882
28722883 u := & CommonTestUtils {
2873- t : t ,
2874- cluster : c ,
2875- roachNodes : nodes ,
2876- mock : mock ,
2877- onlineRestore : onlineRestore ,
2884+ t : t ,
2885+ cluster : c ,
2886+ roachNodes : nodes ,
28782887 }
28792888 u .connCache .cache = cc
2889+
2890+ // Apply all options
2891+ for _ , opt := range opts {
2892+ opt (u )
2893+ }
28802894 return u , nil
28812895}
28822896
@@ -2887,7 +2901,7 @@ func (mvb *mixedVersionBackup) CommonTestUtils(
28872901 mvb .utilsOnce .Do (func () {
28882902 connectFunc := func (node int ) (* gosql.DB , error ) { return h .Connect (node ), nil }
28892903 mvb .commonTestUtils , err = newCommonTestUtils (
2890- ctx , mvb .t , mvb .cluster , connectFunc , mvb .roachNodes , false , false ,
2904+ ctx , mvb .t , mvb .cluster , connectFunc , mvb .roachNodes ,
28912905 )
28922906 })
28932907 return mvb .commonTestUtils , err
0 commit comments