@@ -12,7 +12,7 @@ import (
1212)
1313
1414func TestInitWithAPIKey (t * testing.T ) {
15- client := NewClient ("test-key" , "" , 0 , 0 , 0 , 0 )
15+ client := NewClient (WithAPIKey ( "test-key" ) )
1616 if client .apiKey != "test-key" {
1717 t .Errorf ("expected apiKey=test-key, got %s" , client .apiKey )
1818 }
@@ -22,14 +22,14 @@ func TestInitWithAPIKey(t *testing.T) {
2222}
2323
2424func TestInitWithCustomBaseURL (t * testing.T ) {
25- client := NewClient ("test-key" , "https://custom.api.com/" , 0 , 0 , 0 , 0 )
25+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( "https://custom.api.com/" ) )
2626 if client .baseURL != "https://custom.api.com" {
2727 t .Errorf ("expected baseURL=https://custom.api.com, got %s" , client .baseURL )
2828 }
2929}
3030
3131func TestGetHeadersRaisesWithoutAPIKey (t * testing.T ) {
32- client := NewClient ("" , "" , 0 , 0 , 0 , 0 )
32+ client := NewClient ()
3333 client .apiKey = ""
3434 _ , err := client .getHeaders ()
3535 if err == nil {
@@ -41,7 +41,7 @@ func TestGetHeadersRaisesWithoutAPIKey(t *testing.T) {
4141}
4242
4343func TestGetHeadersReturnsAuthHeader (t * testing.T ) {
44- client := NewClient ("test-key" , "" , 0 , 0 , 0 , 0 )
44+ client := NewClient (WithAPIKey ( "test-key" ) )
4545 headers , err := client .getHeaders ()
4646 if err != nil {
4747 t .Fatalf ("getHeaders error: %v" , err )
@@ -63,7 +63,7 @@ func TestSubmitSuccess(t *testing.T) {
6363 server := httptest .NewServer (mux )
6464 defer server .Close ()
6565
66- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
66+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
6767 requestID , result , err := client .submit ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, false , 0 )
6868 if err != nil {
6969 t .Fatalf ("submit error: %v" , err )
@@ -85,7 +85,7 @@ func TestSubmitFailure(t *testing.T) {
8585 server := httptest .NewServer (mux )
8686 defer server .Close ()
8787
88- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
88+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
8989 _ , _ , err := client .submit ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, false , 0 )
9090 if err == nil {
9191 t .Fatal ("expected error for HTTP 500" )
@@ -104,7 +104,7 @@ func TestGetResultSuccess(t *testing.T) {
104104 server := httptest .NewServer (mux )
105105 defer server .Close ()
106106
107- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
107+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
108108 result , err := client .getResult ("req-123" , 0 )
109109 if err != nil {
110110 t .Fatalf ("getResult error: %v" , err )
@@ -131,7 +131,7 @@ func TestRunSuccess(t *testing.T) {
131131 server := httptest .NewServer (mux )
132132 defer server .Close ()
133133
134- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
134+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
135135 result , err := client .Run ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, WithPollInterval (0.01 ))
136136 if err != nil {
137137 t .Fatalf ("run error: %v" , err )
@@ -161,7 +161,7 @@ func TestRunFailure(t *testing.T) {
161161 server := httptest .NewServer (mux )
162162 defer server .Close ()
163163
164- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
164+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
165165 _ , err := client .Run ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, WithPollInterval (0.01 ))
166166 if err == nil {
167167 t .Fatal ("expected error for failed prediction" )
@@ -205,7 +205,7 @@ func TestUploadFilePath(t *testing.T) {
205205 }
206206 defer os .Remove (tmpFile )
207207
208- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
208+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
209209 url , err := client .Upload (tmpFile )
210210 if err != nil {
211211 t .Fatalf ("upload error: %v" , err )
@@ -216,7 +216,7 @@ func TestUploadFilePath(t *testing.T) {
216216}
217217
218218func TestUploadFileNotFound (t * testing.T ) {
219- client := NewClient ("test-key" , "" , 0 , 0 , 0 , 0 )
219+ client := NewClient (WithAPIKey ( "test-key" ) )
220220 _ , err := client .Upload ("/nonexistent/path/to/file.png" )
221221 if err == nil {
222222 t .Fatal ("expected error for non-existent file" )
@@ -227,7 +227,7 @@ func TestUploadFileNotFound(t *testing.T) {
227227}
228228
229229func TestUploadRaisesWithoutAPIKey (t * testing.T ) {
230- client := NewClient ("" , "" , 0 , 0 , 0 , 0 )
230+ client := NewClient ()
231231 client .apiKey = ""
232232 _ , err := client .Upload ("/some/file.png" )
233233 if err == nil {
@@ -253,7 +253,7 @@ func TestUploadHTTPError(t *testing.T) {
253253 }
254254 defer os .Remove (tmpFile )
255255
256- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
256+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
257257 _ , err := client .Upload (tmpFile )
258258 if err == nil {
259259 t .Fatal ("expected error for HTTP 500" )
@@ -278,7 +278,7 @@ func TestUploadAPIError(t *testing.T) {
278278 }
279279 defer os .Remove (tmpFile )
280280
281- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
281+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
282282 _ , err := client .Upload (tmpFile )
283283 if err == nil {
284284 t .Fatal ("expected error for API error response" )
@@ -298,7 +298,7 @@ func TestRunSyncModeFailure(t *testing.T) {
298298 server := httptest .NewServer (mux )
299299 defer server .Close ()
300300
301- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
301+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
302302 _ , err := client .Run ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, WithSyncMode (true ))
303303 if err == nil {
304304 t .Fatal ("expected error for non-completed status in sync mode" )
@@ -328,7 +328,7 @@ func TestRunTimeout(t *testing.T) {
328328 server := httptest .NewServer (mux )
329329 defer server .Close ()
330330
331- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
331+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
332332 _ , err := client .Run ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, WithTimeout (0.1 ), WithPollInterval (0.01 ))
333333 if err == nil {
334334 t .Fatal ("expected timeout error" )
@@ -474,7 +474,7 @@ func TestRunAllRetriesFailed(t *testing.T) {
474474 server := httptest .NewServer (mux )
475475 defer server .Close ()
476476
477- client := NewClient ("test-key" , server .URL , 0 , 2 , 0 , 0 .01 ) // maxRetries=2
477+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ), WithClientMaxRetries ( 2 ), WithRetryInterval ( 0 .01) ) // maxRetries=2
478478 _ , err := client .Run ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, WithPollInterval (0.01 ), WithMaxRetries (2 ))
479479
480480 if err == nil {
@@ -500,7 +500,7 @@ func TestGetResultConnectionRetry(t *testing.T) {
500500 server := httptest .NewServer (mux )
501501 defer server .Close ()
502502
503- client := NewClient ("test-key" , server .URL , 0 , 0 , 5 , 0.01 )
503+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ), WithMaxConnectionRetries ( 5 ), WithRetryInterval ( 0.01 ) )
504504 _ , err := client .getResult ("req-123" , 0 )
505505
506506 if err == nil {
@@ -518,7 +518,7 @@ func TestGetResultConnectionRetry(t *testing.T) {
518518}
519519
520520func TestIsRetryableError (t * testing.T ) {
521- client := NewClient ("test-key" , "" , 0 , 0 , 0 , 0 )
521+ client := NewClient (WithAPIKey ( "test-key" ) )
522522
523523 tests := []struct {
524524 name string
@@ -560,7 +560,7 @@ func TestSubmitConnectionRetry(t *testing.T) {
560560 server := httptest .NewServer (mux )
561561 defer server .Close ()
562562
563- client := NewClient ("test-key" , server .URL , 0 , 0 , 5 , 0.01 )
563+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ), WithMaxConnectionRetries ( 5 ), WithRetryInterval ( 0.01 ) )
564564 _ , _ , err := client .submit ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, false , 0 )
565565
566566 if err == nil {
@@ -588,7 +588,7 @@ func TestWaitInvalidResponse(t *testing.T) {
588588 server := httptest .NewServer (mux )
589589 defer server .Close ()
590590
591- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
591+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
592592 _ , err := client .wait ("req-123" , 0.1 , 0.01 )
593593
594594 if err == nil {
@@ -609,7 +609,7 @@ func TestGetResultNon200Status(t *testing.T) {
609609 server := httptest .NewServer (mux )
610610 defer server .Close ()
611611
612- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
612+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
613613 _ , err := client .getResult ("req-123" , 0 )
614614
615615 if err == nil {
@@ -635,7 +635,7 @@ func TestSubmitMissingRequestID(t *testing.T) {
635635 server := httptest .NewServer (mux )
636636 defer server .Close ()
637637
638- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
638+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
639639 _ , _ , err := client .submit ("wavespeed-ai/z-image/turbo" , map [string ]any {"prompt" : "test" }, false , 0 )
640640
641641 if err == nil {
@@ -658,7 +658,7 @@ func TestWaitMissingStatus(t *testing.T) {
658658 server := httptest .NewServer (mux )
659659 defer server .Close ()
660660
661- client := NewClient ("test-key" , server .URL , 0 , 0 , 0 , 0 )
661+ client := NewClient (WithAPIKey ( "test-key" ), WithBaseURL ( server .URL ) )
662662 _ , err := client .wait ("req-123" , 0.1 , 0.01 )
663663
664664 if err == nil {
0 commit comments