11package hosted
22
33import (
4+ "context"
5+ "net/http"
46 "testing"
57 "time"
8+
9+ "github.com/gastownhall/wasteland/internal/dolthubauth"
610)
711
12+ type roundTripFunc func (* http.Request ) (* http.Response , error )
13+
14+ func (fn roundTripFunc ) RoundTrip (req * http.Request ) (* http.Response , error ) {
15+ return fn (req )
16+ }
17+
818func TestAuthServiceWorkspaceResolver_InvalidateConnectionClearsPendingCaches (t * testing.T ) {
919 resolver := NewAuthServiceWorkspaceResolver (nil , NewSessionStore ())
1020 cache1 := newPendingUpstreamCache (nil , "hop" , "wl-commons" , time .Hour )
@@ -24,3 +34,37 @@ func TestAuthServiceWorkspaceResolver_InvalidateConnectionClearsPendingCaches(t
2434 t .Fatal ("expected unrelated pending cache to remain" )
2535 }
2636}
37+
38+ func TestAuthServiceWorkspaceResolver_BuildClientWarmsPendingCache (t * testing.T ) {
39+ resolver := NewAuthServiceWorkspaceResolver (nil , NewSessionStore ())
40+ session := & UserSession {
41+ SubjectID : "subject-1" ,
42+ ConnectionID : "conn-1" ,
43+ }
44+ conn := & dolthubauth.ConnectionResponse {
45+ ConnectionID : "conn-1" ,
46+ SubjectID : "subject-1" ,
47+ RigHandle : "alice" ,
48+ }
49+ wl := dolthubauth.WastelandConfig {
50+ Upstream : "hop/wl-commons" ,
51+ ForkOrg : "alice" ,
52+ ForkDB : "wl-commons" ,
53+ Mode : "pr" ,
54+ }
55+
56+ client := & http.Client {Transport : roundTripFunc (func (* http.Request ) (* http.Response , error ) {
57+ return nil , context .Canceled
58+ })}
59+
60+ if _ , err := resolver .buildClient (session , conn , client , wl ); err != nil {
61+ t .Fatalf ("buildClient() error = %v" , err )
62+ }
63+
64+ key := "conn-1:hop/wl-commons"
65+ cache , ok := resolver .pendingCache [key ]
66+ if ! ok {
67+ t .Fatalf ("expected pending cache %q to be created during build" , key )
68+ }
69+ cache .Stop ()
70+ }
0 commit comments