@@ -17,7 +17,6 @@ import (
17
17
"net/url"
18
18
"os"
19
19
"path/filepath"
20
- "reflect"
21
20
"strings"
22
21
"sync"
23
22
"testing"
@@ -826,35 +825,26 @@ func TestRefreshInMultipleRequests(t *testing.T) {
826
825
Token string
827
826
Tenant string
828
827
}
829
- ch := make (chan tokenResult , 10 )
828
+ tokenOneCchecker := false
829
+ tokenTwoCchecker := false
830
+
831
+ ch := make (chan tokenResult , 14 )
830
832
var mu sync.Mutex // Mutex to protect access to expectedResponse
831
- expectedResponse := []tokenResult {
832
- {Token : "new token" , Tenant : "firstTentant" },
833
- {Token : "new token" , Tenant : "firstTentant" },
834
- {Token : "first token" , Tenant : "secondTentant" },
835
- {Token : "first token" , Tenant : "secondTentant" },
836
- {Token : "first token" , Tenant : "secondTentant" },
837
- {Token : "first token" , Tenant : "firstTentant" },
838
- {Token : "first token" , Tenant : "secondTentant" },
839
- {Token : "new token" , Tenant : "firstTentant" },
840
- {Token : "new token" , Tenant : "firstTentant" },
841
- {Token : "first token" , Tenant : "secondTentant" },
842
- }
843
833
gotResponse := []tokenResult {}
844
834
mockClient .AppendResponse (
845
- mock .WithBody ([]byte (fmt .Sprintf (`{"access_token":%q,"expires_in":%d,"refresh_in":%d,"token_type":"Bearer"}` , secondToken , expiresIn , refreshIn ))), mock .WithCallback (func (req * http.Request ) {
835
+ mock .WithBody ([]byte (fmt .Sprintf (`{"access_token":%q,"expires_in":%d,"refresh_in":%d,"token_type":"Bearer"}` , secondToken + "firstTenant" , expiresIn , refreshIn ))), mock .WithCallback (func (req * http.Request ) {
846
836
time .Sleep (150 * time .Millisecond )
847
837
}),
848
838
)
849
839
mockClient .AppendResponse (
850
- mock .WithBody ([]byte (fmt .Sprintf (`{"access_token":%q,"expires_in":%d,"refresh_in":%d,"token_type":"Bearer"}` , secondToken , expiresIn , refreshIn ))), mock .WithCallback (func (req * http.Request ) {
840
+ mock .WithBody ([]byte (fmt .Sprintf (`{"access_token":%q,"expires_in":%d,"refresh_in":%d,"token_type":"Bearer"}` , secondToken + "secondTenant" , expiresIn , refreshIn ))), mock .WithCallback (func (req * http.Request ) {
851
841
time .Sleep (100 * time .Millisecond )
852
842
mu .Lock ()
853
843
base .GetCurrentTime = originalTime
854
844
mu .Unlock ()
855
845
}),
856
846
)
857
- for i := 0 ; i < 5 ; i ++ {
847
+ for i := 0 ; i < 7 ; i ++ {
858
848
wg .Add (1 )
859
849
wg .Add (1 )
860
850
time .Sleep (50 * time .Millisecond )
@@ -865,6 +855,13 @@ func TestRefreshInMultipleRequests(t *testing.T) {
865
855
t .Error (err )
866
856
return
867
857
}
858
+ if ar .AccessToken == secondToken + "firstTenant" && ar .Metadata .TokenSource == base .IdentityProvider {
859
+ if tokenOneCchecker {
860
+ t .Error ("Error can only call this once" )
861
+ } else {
862
+ tokenOneCchecker = true
863
+ }
864
+ }
868
865
ch <- tokenResult {Token : ar .AccessToken , Tenant : "firstTentant" } // Send result to channel
869
866
}()
870
867
go func () {
@@ -875,6 +872,13 @@ func TestRefreshInMultipleRequests(t *testing.T) {
875
872
t .Error (err )
876
873
return
877
874
}
875
+ if ar .AccessToken == secondToken + "secondTenant" && ar .Metadata .TokenSource == base .IdentityProvider {
876
+ if tokenTwoCchecker {
877
+ t .Error ("Error can only call this once" )
878
+ } else {
879
+ tokenTwoCchecker = true
880
+ }
881
+ }
878
882
ch <- tokenResult {Token : ar .AccessToken , Tenant : "secondTentant" } // Send result to channel
879
883
}()
880
884
}
@@ -885,8 +889,8 @@ func TestRefreshInMultipleRequests(t *testing.T) {
885
889
gotResponse = append (gotResponse , s )
886
890
mu .Unlock () // Release lock after modifying expectedResponse
887
891
}
888
- if reflect . DeepEqual ( gotResponse , expectedResponse ) {
889
- t .Error ("gotResponse and expectedResponse are not equal " )
892
+ if ! tokenOneCchecker && ! tokenTwoCchecker {
893
+ t .Error ("Error should be called at least once " )
890
894
}
891
895
}()
892
896
wg .Wait ()
0 commit comments