@@ -1098,36 +1098,20 @@ func TestCustomRestyClientIsUsed(t *testing.T) {
10981098 assert .True (t , hasCustomHeader , "Expected custom resty header" )
10991099}
11001100
1101- func TestRestyClientOverridesHTTPClient (t * testing.T ) {
1102- ctx := context .Background ()
1103-
1104- var customHeader string
1105- server := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {
1106- customHeader = req .Header .Get ("X-Test-Client" )
1107- rw .Header ().Set ("Content-Type" , "application/json" )
1108- rw .WriteHeader (http .StatusOK )
1109- _ , err := io .WriteString (rw , fixtures .FlagsJson )
1110- assert .NoError (t , err )
1111- }))
1112- defer server .Close ()
1113-
1101+ func TestRestyClientOverridesHTTPClientShouldPanic (t * testing.T ) {
11141102 httpClient := & http.Client {
11151103 Transport : roundTripperWithHeader ("X-Test-Client" , "http" ),
11161104 }
11171105
11181106 restyClient := resty .New ().
11191107 SetHeader ("X-Test-Client" , "resty" )
11201108
1121- client := flagsmith .NewClient (fixtures .EnvironmentAPIKey ,
1122- flagsmith .WithHTTPClient (httpClient ),
1123- flagsmith .WithRestyClient (restyClient ),
1124- flagsmith .WithBaseURL (server .URL + "/api/v1/" ))
1125-
1126- flags , err := client .GetFlags (ctx , nil )
1127-
1128- assert .NoError (t , err )
1129- assert .Equal (t , 1 , len (flags .AllFlags ()))
1130- assert .Equal (t , "resty" , customHeader , "Expected resty header" )
1109+ assert .Panics (t , func () {
1110+ _ = flagsmith .NewClient (fixtures .EnvironmentAPIKey ,
1111+ flagsmith .WithHTTPClient (httpClient ),
1112+ flagsmith .WithRestyClient (restyClient ),
1113+ flagsmith .WithBaseURL ("http://example.com/api/v1/" ))
1114+ }, "Expected panic when both HTTP and Resty clients are provided" )
11311115}
11321116
11331117func TestDefaultRestyClientIsUsed (t * testing.T ) {
@@ -1157,3 +1141,39 @@ func TestDefaultRestyClientIsUsed(t *testing.T) {
11571141 assert .True (t , serverCalled , "Expected server to be" )
11581142 assert .Equal (t , 1 , len (flags .AllFlags ()))
11591143}
1144+
1145+ func TestCustomClientOptionsShoudPanic (t * testing.T ) {
1146+ restyClient := resty .New ()
1147+
1148+ testCases := []struct {
1149+ name string
1150+ option flagsmith.Option
1151+ }{
1152+ {
1153+ name : "WithRequestTimeout" ,
1154+ option : flagsmith .WithRequestTimeout (5 * time .Second ),
1155+ },
1156+ {
1157+ name : "WithRetries" ,
1158+ option : flagsmith .WithRetries (3 , time .Second ),
1159+ },
1160+ {
1161+ name : "WithCustomHeaders" ,
1162+ option : flagsmith .WithCustomHeaders (map [string ]string {"X-Custom" : "value" }),
1163+ },
1164+ {
1165+ name : "WithProxy" ,
1166+ option : flagsmith .WithProxy ("http://proxy.example.com" ),
1167+ },
1168+ }
1169+
1170+ for _ , test := range testCases {
1171+ t .Run (test .name , func (t * testing.T ) {
1172+ assert .Panics (t , func () {
1173+ _ = flagsmith .NewClient (fixtures .EnvironmentAPIKey ,
1174+ flagsmith .WithRestyClient (restyClient ),
1175+ test .option )
1176+ }, "Expected panic when using %s with custom resty client" , test .name )
1177+ })
1178+ }
1179+ }
0 commit comments