@@ -46,11 +46,20 @@ func TestLoginURLResolution(t *testing.T) {
4646 type capturedLogin struct {
4747 url string
4848 oidcToken string
49+ calls int
4950 }
5051
5152 credsF := func () (workspace.Credentials , error ) {
5253 return workspace.Credentials {Current : "https://stored-creds.example.com" }, nil
5354 }
55+ configuredWorkspace := & pkgWorkspace.MockContext {
56+ ReadProjectF : func (string ) (* workspace.Project , string , error ) {
57+ return & workspace.Project {
58+ Backend : & workspace.ProjectBackend {URL : "https://project-backend.example.com" },
59+ }, "" , nil
60+ },
61+ GetStoredCredentialsF : credsF ,
62+ }
5463
5564 tests := []struct {
5665 name string
@@ -63,25 +72,34 @@ func TestLoginURLResolution(t *testing.T) {
6372 expectedError string
6473 }{
6574 {
66- name : "command argument takes precedence" ,
67- args : []string {"s3://my-bucket" },
68- ws : & pkgWorkspace.MockContext {},
75+ name : "command argument takes precedence" ,
76+ args : []string {"s3://my-bucket" },
77+ ws : configuredWorkspace ,
78+ envVars : map [string ]string {
79+ "PULUMI_BACKEND_URL" : "https://env-backend.example.com" ,
80+ },
6981 expectedURL : "s3://my-bucket" ,
7082 },
7183 {
7284 name : "cloud-url flag takes precedence" ,
7385 flags : map [string ]string {
7486 "cloud-url" : "https://custom.example.com" ,
7587 },
76- ws : & pkgWorkspace.MockContext {},
88+ ws : configuredWorkspace ,
89+ envVars : map [string ]string {
90+ "PULUMI_BACKEND_URL" : "https://env-backend.example.com" ,
91+ },
7792 expectedURL : "https://custom.example.com" ,
7893 },
7994 {
8095 name : "local flag sets file:// backend" ,
8196 flags : map [string ]string {
8297 "local" : "true" ,
8398 },
84- ws : & pkgWorkspace.MockContext {},
99+ ws : configuredWorkspace ,
100+ envVars : map [string ]string {
101+ "PULUMI_BACKEND_URL" : "https://env-backend.example.com" ,
102+ },
85103 expectedURL : "file://~" ,
86104 },
87105 {
@@ -106,24 +124,15 @@ func TestLoginURLResolution(t *testing.T) {
106124 },
107125 {
108126 name : "environment variable used when no explicit URL" ,
109- ws : & pkgWorkspace.MockContext {
110- GetStoredCredentialsF : credsF ,
111- },
127+ ws : configuredWorkspace ,
112128 envVars : map [string ]string {
113129 "PULUMI_BACKEND_URL" : "https://env-backend.example.com" ,
114130 },
115131 expectedURL : "https://env-backend.example.com" ,
116132 },
117133 {
118- name : "project backend URL used when no env var" ,
119- ws : & pkgWorkspace.MockContext {
120- ReadProjectF : func (string ) (* workspace.Project , string , error ) {
121- return & workspace.Project {
122- Backend : & workspace.ProjectBackend {URL : "https://project-backend.example.com" },
123- }, "" , nil
124- },
125- GetStoredCredentialsF : credsF ,
126- },
134+ name : "project backend URL used when no env var" ,
135+ ws : configuredWorkspace ,
127136 expectedURL : "https://project-backend.example.com" ,
128137 },
129138 {
@@ -190,6 +199,7 @@ func TestLoginURLResolution(t *testing.T) {
190199 insecure bool ,
191200 color colors.Colorization ,
192201 ) (pkgBackend.Backend , error ) {
202+ captured .calls ++
193203 captured .url = url
194204 return & pkgBackend.MockBackend {
195205 URLF : func () string { return url },
@@ -208,6 +218,7 @@ func TestLoginURLResolution(t *testing.T) {
208218 insecure bool ,
209219 authContext workspace.AuthContext ,
210220 ) (pkgBackend.Backend , error ) {
221+ captured .calls ++
211222 captured .url = url
212223 captured .oidcToken = authContext .Token
213224 return & pkgBackend.MockBackend {
@@ -241,13 +252,16 @@ func TestLoginURLResolution(t *testing.T) {
241252
242253 if tt .expectError {
243254 require .Error (t , err )
255+ assert .Zero (t , captured .calls )
244256 if tt .expectedError != "" {
245257 require .ErrorContains (t , err , tt .expectedError )
246258 }
247259 } else {
248260 require .NoError (t , err )
261+ assert .Equal (t , 1 , captured .calls )
249262 assert .Equal (t , tt .expectedURL , captured .url ,
250263 "login should be called with expected URL" )
264+ assert .Equal (t , tt .flags ["oidc-token" ], captured .oidcToken )
251265 }
252266 })
253267 }
0 commit comments