@@ -59,7 +59,7 @@ func getTestHttpServer(t *testing.T, expectedPath string, expectedEnvKey string,
5959func TestClientErrorsIfLocalEvaluationWithNonServerSideKey (t * testing.T ) {
6060 // When, Then
6161 assert .Panics (t , func () {
62- _ = flagsmith .NewClient ("key" , flagsmith .WithLocalEvaluation (context .Background ()))
62+ _ = flagsmith .MustNewClient ("key" , flagsmith .WithLocalEvaluation (context .Background ()))
6363 })
6464}
6565
@@ -69,13 +69,13 @@ func TestClientErrorsIfOfflineModeWithoutOfflineHandler(t *testing.T) {
6969 if r := recover (); r != nil {
7070 // Then
7171 errMsg := fmt .Sprintf ("%v" , r )
72- expectedErrMsg := "offline handler must be provided to use offline mode. "
72+ expectedErrMsg := "offline handler must be provided to use offline mode"
7373 assert .Equal (t , expectedErrMsg , errMsg , "Unexpected error message" )
7474 }
7575 }()
7676
7777 // Trigger panic
78- _ = flagsmith .NewClient ("key" , flagsmith .WithOfflineMode ())
78+ _ = flagsmith .MustNewClient ("key" , flagsmith .WithOfflineMode ())
7979}
8080
8181func TestClientErrorsIfDefaultHandlerAndOfflineHandlerAreBothSet (t * testing.T ) {
@@ -89,13 +89,13 @@ func TestClientErrorsIfDefaultHandlerAndOfflineHandlerAreBothSet(t *testing.T) {
8989 if r := recover (); r != nil {
9090 // Then
9191 errMsg := fmt .Sprintf ("%v" , r )
92- expectedErrMsg := "default flag handler and offline handler cannot be used together. "
92+ expectedErrMsg := "default flag handler and offline handler cannot be used together"
9393 assert .Equal (t , expectedErrMsg , errMsg , "Unexpected error message" )
9494 }
9595 }()
9696
9797 // Trigger panic
98- _ = flagsmith .NewClient ("key" ,
98+ _ = flagsmith .MustNewClient ("key" ,
9999 flagsmith .WithOfflineHandler (offlineHandler ),
100100 flagsmith .WithDefaultHandler (func (featureName string ) (flagsmith.Flag , error ) {
101101 return flagsmith.Flag {}, nil
@@ -112,13 +112,13 @@ func TestClientErrorsIfLocalEvaluationModeAndOfflineHandlerAreBothSet(t *testing
112112 if r := recover (); r != nil {
113113 // Then
114114 errMsg := fmt .Sprintf ("%v" , r )
115- expectedErrMsg := "local evaluation and offline handler cannot be used together. "
115+ expectedErrMsg := "local evaluation and offline handler cannot be used together"
116116 assert .Equal (t , expectedErrMsg , errMsg , "Unexpected error message" )
117117 }
118118 }()
119119
120120 // Trigger panic
121- _ = flagsmith .NewClient ("key" ,
121+ _ = flagsmith .MustNewClient ("key" ,
122122 flagsmith .WithOfflineHandler (offlineHandler ),
123123 flagsmith .WithLocalEvaluation (context .Background ()))
124124}
@@ -147,7 +147,7 @@ func TestClientUpdatesEnvironmentOnStartForLocalEvaluation(t *testing.T) {
147147 defer server .Close ()
148148
149149 // When
150- _ = flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
150+ _ = flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
151151 flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
152152
153153 // Sleep to ensure that the server has time to update the environment
@@ -183,7 +183,7 @@ func TestClientUpdatesEnvironmentOnEachRefresh(t *testing.T) {
183183 defer server .Close ()
184184
185185 // When
186- _ = flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
186+ _ = flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
187187 flagsmith .WithEnvironmentRefreshInterval (100 * time .Millisecond ),
188188 flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
189189
@@ -204,7 +204,7 @@ func TestGetFlags(t *testing.T) {
204204 defer server .Close ()
205205
206206 // When
207- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
207+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
208208
209209 flags , err := client .GetEnvironmentFlags (context .Background ())
210210
@@ -228,7 +228,7 @@ func TestGetEnvironmentFlags(t *testing.T) {
228228 defer server .Close ()
229229
230230 // When
231- client := flagsmith .NewClient (expectedEnvKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
231+ client := flagsmith .MustNewClient (expectedEnvKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
232232
233233 _ , err := client .GetEnvironmentFlags (ctx )
234234 assert .NoError (t , err )
@@ -241,7 +241,7 @@ func TestGetFlagsEnvironmentEvaluationContextIdentity(t *testing.T) {
241241 defer server .Close ()
242242
243243 // When
244- client := flagsmith .NewClient (expectedEnvKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
244+ client := flagsmith .MustNewClient (expectedEnvKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
245245
246246 _ , err := client .GetFlags (
247247 context .Background (),
@@ -259,7 +259,7 @@ func TestGetEnvironmentFlagsUseslocalEnvironmentWhenAvailable(t *testing.T) {
259259 defer server .Close ()
260260
261261 // When
262- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
262+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
263263 flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
264264 err := client .UpdateEnvironment (ctx )
265265
@@ -295,7 +295,7 @@ func TestGetEnvironmentFlagsCallsAPIWhenLocalEnvironmentNotAvailable(t *testing.
295295 defer server .Close ()
296296
297297 // When
298- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
298+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
299299 flagsmith .WithDefaultHandler (func (featureName string ) (flagsmith.Flag , error ) {
300300 return flagsmith.Flag {}, nil
301301 }))
@@ -332,7 +332,7 @@ func TestGetIdentityFlagsUseslocalEnvironmentWhenAvailable(t *testing.T) {
332332 server := httptest .NewServer (http .HandlerFunc (fixtures .EnvironmentDocumentHandler ))
333333 defer server .Close ()
334334 // When
335- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
335+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
336336 flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
337337 err := client .UpdateEnvironment (ctx )
338338
@@ -358,7 +358,7 @@ func TestGetIdentityFlagsUseslocalOverridesWhenAvailable(t *testing.T) {
358358 server := httptest .NewServer (http .HandlerFunc (fixtures .EnvironmentDocumentHandler ))
359359 defer server .Close ()
360360 // When
361- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
361+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
362362 flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
363363 err := client .UpdateEnvironment (ctx )
364364
@@ -423,7 +423,7 @@ func TestGetIdentityFlagsCallsAPIWhenLocalEnvironmentNotAvailableWithTraits(t *t
423423 }))
424424 defer server .Close ()
425425
426- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey ,
426+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey ,
427427 flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
428428
429429 flags , err := client .GetFlags (ctx , flagsmith .NewEvaluationContext ("test_identity" , traits ))
@@ -453,7 +453,7 @@ func TestDefaultHandlerIsUsedWhenNoMatchingEnvironmentFlagReturned(t *testing.T)
453453 defer server .Close ()
454454
455455 // When
456- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
456+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
457457 flagsmith .WithDefaultHandler (func (featureName string ) (flagsmith.Flag , error ) {
458458 return flagsmith.Flag {}, nil
459459 }))
@@ -485,7 +485,7 @@ func TestDefaultHandlerIsUsedWhenTimeout(t *testing.T) {
485485 defer server .Close ()
486486
487487 // When
488- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
488+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
489489 flagsmith .WithRequestTimeout (10 * time .Millisecond ),
490490 flagsmith .WithDefaultHandler (func (featureName string ) (flagsmith.Flag , error ) {
491491 return flagsmith.Flag {}, nil
@@ -508,7 +508,7 @@ func TestDefaultHandlerIsUsedWhenRequestFails(t *testing.T) {
508508 defer server .Close ()
509509
510510 // When
511- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
511+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
512512 flagsmith .WithDefaultHandler (func (featureName string ) (flagsmith.Flag , error ) {
513513 return flagsmith.Flag {}, nil
514514 }))
@@ -530,7 +530,7 @@ func TestFlagsmithAPIErrorIsReturnedIfRequestFailsWithoutDefaultHandler(t *testi
530530 defer server .Close ()
531531
532532 // When
533- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
533+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
534534
535535 _ , err := client .GetEnvironmentFlags (ctx )
536536 assert .Error (t , err )
@@ -544,7 +544,7 @@ func TestGetIdentitySegmentsNoTraits(t *testing.T) {
544544 server := httptest .NewServer (http .HandlerFunc (fixtures .EnvironmentDocumentHandler ))
545545 defer server .Close ()
546546
547- client := flagsmith .NewClient (
547+ client := flagsmith .MustNewClient (
548548 fixtures .EnvironmentAPIKey ,
549549 flagsmith .WithLocalEvaluation (ctx ),
550550 flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
@@ -566,7 +566,7 @@ func TestGetIdentitySegmentsWithTraits(t *testing.T) {
566566 server := httptest .NewServer (http .HandlerFunc (fixtures .EnvironmentDocumentHandler ))
567567 defer server .Close ()
568568
569- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
569+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ),
570570 flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
571571
572572 err := client .UpdateEnvironment (ctx )
@@ -604,7 +604,7 @@ func TestBulkIdentifyReturnsErrorIfBatchSizeIsTooLargeToProcess(t *testing.T) {
604604
605605 }))
606606 defer server .Close ()
607- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
607+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
608608
609609 // When
610610 err := client .BulkIdentify (ctx , data )
@@ -623,7 +623,7 @@ func TestBulkIdentifyReturnsErrorIfServerReturns404(t *testing.T) {
623623 rw .WriteHeader (http .StatusNotFound )
624624 }))
625625 defer server .Close ()
626- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
626+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
627627
628628 // When
629629 err := client .BulkIdentify (ctx , data )
@@ -663,7 +663,7 @@ func TestBulkIdentify(t *testing.T) {
663663 }))
664664 defer server .Close ()
665665
666- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
666+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
667667
668668 // When
669669 err := client .BulkIdentify (ctx , data )
@@ -678,7 +678,7 @@ func TestWithProxyClientOption(t *testing.T) {
678678 server := httptest .NewServer (http .HandlerFunc (fixtures .EnvironmentDocumentHandler ))
679679 defer server .Close ()
680680
681- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ), flagsmith .WithProxy (server .URL ),
681+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithLocalEvaluation (ctx ), flagsmith .WithProxy (server .URL ),
682682 flagsmith .WithBaseURL ("http://some-other-url-that-should-not-be-used/api/v1/" ))
683683
684684 err := client .UpdateEnvironment (ctx )
@@ -706,7 +706,7 @@ func TestOfflineMode(t *testing.T) {
706706 offlineHandler , err := flagsmith .NewLocalFileHandler (envJsonPath )
707707 assert .NoError (t , err )
708708
709- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey , flagsmith .WithOfflineMode (), flagsmith .WithOfflineHandler (offlineHandler ))
709+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey , flagsmith .WithOfflineMode (), flagsmith .WithOfflineHandler (offlineHandler ))
710710
711711 // Then
712712 flags , err := client .GetEnvironmentFlags (ctx )
@@ -746,7 +746,7 @@ func TestPollErrorHandlerIsUsedWhenPollFails(t *testing.T) {
746746 defer server .Close ()
747747
748748 // When
749- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey ,
749+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey ,
750750 flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
751751 flagsmith .WithErrorHandler (func (handler * flagsmith.FlagsmithAPIError ) {
752752 capturedError = handler .Err
@@ -815,7 +815,7 @@ func TestRealtime(t *testing.T) {
815815 defer server .Close ()
816816
817817 // When
818- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey ,
818+ client := flagsmith .MustNewClient (fixtures .EnvironmentAPIKey ,
819819 flagsmith .WithBaseURL (server .URL + "/api/v1/" ),
820820 flagsmith .WithLocalEvaluation (ctx ),
821821 flagsmith .WithRealtime (),
0 commit comments