@@ -635,6 +635,65 @@ func TestAuthSession_Do_Timeout(t *testing.T) {
635635 t .Errorf ("Do() call did not error with context.DeadlineExceeded, got=%v" , err )
636636 }
637637 })
638+
639+ t .Run ("Do() follows Context set in AuthSession config" , func (t * testing.T ) {
640+ mux := http .NewServeMux ()
641+ setupApi40Login (mux , foreverValidTestToken , http .StatusOK )
642+ server := httptest .NewServer (mux )
643+ defer server .Close ()
644+
645+ mux .HandleFunc ("/api" + apiVersion + path , func (w http.ResponseWriter , r * http.Request ) {
646+ time .Sleep (4 * time .Second )
647+ })
648+
649+ ctx , cncl := context .WithTimeout (context .Background (), 1 * time .Second )
650+ defer cncl ()
651+
652+ session := NewAuthSession (ApiSettings {
653+ BaseUrl : server .URL ,
654+ ApiVersion : apiVersion ,
655+ Context : ctx ,
656+ })
657+
658+ err := session .Do (nil , "GET" , apiVersion , path , nil , nil , nil )
659+
660+ if err == nil {
661+ t .Errorf ("Do() call did not error/timeout" )
662+ } else if ! errors .Is (err , context .DeadlineExceeded ) {
663+ t .Errorf ("Do() call did not error with context.DeadlineExceeded, got=%v" , err )
664+ }
665+ })
666+
667+ t .Run ("Do() follows Context set in Do()'s options" , func (t * testing.T ) {
668+ mux := http .NewServeMux ()
669+ setupApi40Login (mux , foreverValidTestToken , http .StatusOK )
670+ server := httptest .NewServer (mux )
671+ defer server .Close ()
672+
673+ mux .HandleFunc ("/api" + apiVersion + path , func (w http.ResponseWriter , r * http.Request ) {
674+ time .Sleep (4 * time .Second )
675+ })
676+
677+ ctx , cncl := context .WithTimeout (context .Background (), 1 * time .Second )
678+ defer cncl ()
679+
680+ session := NewAuthSession (ApiSettings {
681+ BaseUrl : server .URL ,
682+ ApiVersion : apiVersion ,
683+ })
684+
685+ options := ApiSettings {
686+ Context : ctx ,
687+ }
688+
689+ err := session .Do (nil , "GET" , apiVersion , path , nil , nil , & options )
690+
691+ if err == nil {
692+ t .Errorf ("Do() call did not error/timeout" )
693+ } else if ! errors .Is (err , context .DeadlineExceeded ) {
694+ t .Errorf ("Do() call did not error with context.DeadlineExceeded, got=%v" , err )
695+ }
696+ })
638697}
639698
640699func TestSetQuery (t * testing.T ) {
0 commit comments