@@ -115,6 +115,11 @@ func TestSetGetAuthField(t *testing.T) {
115115
116116 for _ , tt := range tests {
117117 t .Run (tt .description , func (t * testing.T ) {
118+ activeProfile , err := config .GetProfile ()
119+ if err != nil {
120+ t .Errorf ("get profile: %v" , err )
121+ }
122+
118123 if ! tt .keyringFails {
119124 keyring .MockInit ()
120125 } else {
@@ -142,12 +147,12 @@ func TestSetGetAuthField(t *testing.T) {
142147 }
143148
144149 if ! tt .keyringFails {
145- err = deleteAuthFieldInKeyring (key )
150+ err = deleteAuthFieldInKeyring (activeProfile , key )
146151 if err != nil {
147152 t .Errorf ("Post-test cleanup failed: remove field \" %s\" from keyring: %v. Please remove it manually" , key , err )
148153 }
149154 } else {
150- err = deleteAuthFieldInEncodedTextFile (key )
155+ err = deleteAuthFieldInEncodedTextFile (activeProfile , key )
151156 if err != nil {
152157 t .Errorf ("Post-test cleanup failed: remove field \" %s\" from text file: %v. Please remove it manually" , key , err )
153158 }
@@ -174,9 +179,11 @@ func TestSetGetAuthFieldKeyring(t *testing.T) {
174179 description string
175180 valueAssignments []valueAssignment
176181 expectedValues map [authFieldKey ]string
182+ activeProfile string
177183 }{
178184 {
179- description : "simple assignments" ,
185+ description : "simple assignments with default profile" ,
186+ activeProfile : "" ,
180187 valueAssignments : []valueAssignment {
181188 {
182189 key : testField1 ,
@@ -193,7 +200,48 @@ func TestSetGetAuthFieldKeyring(t *testing.T) {
193200 },
194201 },
195202 {
196- description : "overlapping assignments" ,
203+ description : "overlapping assignments with default profile" ,
204+ activeProfile : "" ,
205+ valueAssignments : []valueAssignment {
206+ {
207+ key : testField1 ,
208+ value : testValue1 ,
209+ },
210+ {
211+ key : testField2 ,
212+ value : testValue2 ,
213+ },
214+ {
215+ key : testField1 ,
216+ value : testValue3 ,
217+ },
218+ },
219+ expectedValues : map [authFieldKey ]string {
220+ testField1 : testValue3 ,
221+ testField2 : testValue2 ,
222+ },
223+ },
224+ {
225+ description : "simple assignments with testProfile" ,
226+ activeProfile : "testProfile" ,
227+ valueAssignments : []valueAssignment {
228+ {
229+ key : testField1 ,
230+ value : testValue1 ,
231+ },
232+ {
233+ key : testField2 ,
234+ value : testValue2 ,
235+ },
236+ },
237+ expectedValues : map [authFieldKey ]string {
238+ testField1 : testValue1 ,
239+ testField2 : testValue2 ,
240+ },
241+ },
242+ {
243+ description : "overlapping assignments with testProfile" ,
244+ activeProfile : "testProfile" ,
197245 valueAssignments : []valueAssignment {
198246 {
199247 key : testField1 ,
@@ -220,7 +268,7 @@ func TestSetGetAuthFieldKeyring(t *testing.T) {
220268 keyring .MockInit ()
221269
222270 for _ , assignment := range tt .valueAssignments {
223- err := setAuthFieldInKeyring (assignment .key , assignment .value )
271+ err := setAuthFieldInKeyring (tt . activeProfile , assignment .key , assignment .value )
224272 if err != nil {
225273 t .Fatalf ("Failed to set \" %s\" as \" %s\" : %v" , assignment .key , assignment .value , err )
226274 }
@@ -231,15 +279,15 @@ func TestSetGetAuthFieldKeyring(t *testing.T) {
231279 }
232280
233281 for key , valueExpected := range tt .expectedValues {
234- value , err := getAuthFieldFromKeyring (key )
282+ value , err := getAuthFieldFromKeyring (tt . activeProfile , key )
235283 if err != nil {
236284 t .Errorf ("Failed to get value of \" %s\" : %v" , key , err )
237285 continue
238286 } else if value != valueExpected {
239287 t .Errorf ("Value of field \" %s\" is wrong: expected \" %s\" , got \" %s\" " , key , valueExpected , value )
240288 }
241289
242- err = deleteAuthFieldInKeyring (key )
290+ err = deleteAuthFieldInKeyring (tt . activeProfile , key )
243291 if err != nil {
244292 t .Errorf ("Post-test cleanup failed: remove field \" %s\" from keyring: %v. Please remove it manually" , key , err )
245293 }
@@ -263,11 +311,13 @@ func TestSetGetAuthFieldEncodedTextFile(t *testing.T) {
263311
264312 tests := []struct {
265313 description string
314+ activeProfile string
266315 valueAssignments []valueAssignment
267316 expectedValues map [authFieldKey ]string
268317 }{
269318 {
270- description : "simple assignments" ,
319+ description : "simple assignments with default profile" ,
320+ activeProfile : "" ,
271321 valueAssignments : []valueAssignment {
272322 {
273323 key : testField1 ,
@@ -284,7 +334,48 @@ func TestSetGetAuthFieldEncodedTextFile(t *testing.T) {
284334 },
285335 },
286336 {
287- description : "overlapping assignments" ,
337+ description : "overlapping assignments with default profile" ,
338+ activeProfile : "" ,
339+ valueAssignments : []valueAssignment {
340+ {
341+ key : testField1 ,
342+ value : testValue1 ,
343+ },
344+ {
345+ key : testField2 ,
346+ value : testValue2 ,
347+ },
348+ {
349+ key : testField1 ,
350+ value : testValue3 ,
351+ },
352+ },
353+ expectedValues : map [authFieldKey ]string {
354+ testField1 : testValue3 ,
355+ testField2 : testValue2 ,
356+ },
357+ },
358+ {
359+ description : "simple assignments with testProfile" ,
360+ activeProfile : "testProfile" ,
361+ valueAssignments : []valueAssignment {
362+ {
363+ key : testField1 ,
364+ value : testValue1 ,
365+ },
366+ {
367+ key : testField2 ,
368+ value : testValue2 ,
369+ },
370+ },
371+ expectedValues : map [authFieldKey ]string {
372+ testField1 : testValue1 ,
373+ testField2 : testValue2 ,
374+ },
375+ },
376+ {
377+ description : "overlapping assignments with testProfile" ,
378+ activeProfile : "testProfile" ,
288379 valueAssignments : []valueAssignment {
289380 {
290381 key : testField1 ,
@@ -309,7 +400,7 @@ func TestSetGetAuthFieldEncodedTextFile(t *testing.T) {
309400 for _ , tt := range tests {
310401 t .Run (tt .description , func (t * testing.T ) {
311402 for _ , assignment := range tt .valueAssignments {
312- err := setAuthFieldInEncodedTextFile (assignment .key , assignment .value )
403+ err := setAuthFieldInEncodedTextFile (tt . activeProfile , assignment .key , assignment .value )
313404 if err != nil {
314405 t .Fatalf ("Failed to set \" %s\" as \" %s\" : %v" , assignment .key , assignment .value , err )
315406 }
@@ -320,15 +411,15 @@ func TestSetGetAuthFieldEncodedTextFile(t *testing.T) {
320411 }
321412
322413 for key , valueExpected := range tt .expectedValues {
323- value , err := getAuthFieldFromEncodedTextFile (key )
414+ value , err := getAuthFieldFromEncodedTextFile (tt . activeProfile , key )
324415 if err != nil {
325416 t .Errorf ("Failed to get value of \" %s\" : %v" , key , err )
326417 continue
327418 } else if value != valueExpected {
328419 t .Errorf ("Value of field \" %s\" is wrong: expected \" %s\" , got \" %s\" " , key , valueExpected , value )
329420 }
330421
331- err = deleteAuthFieldInEncodedTextFile (key )
422+ err = deleteAuthFieldInEncodedTextFile (tt . activeProfile , key )
332423 if err != nil {
333424 t .Errorf ("Post-test cleanup failed: remove field \" %s\" from text file: %v. Please remove it manually" , key , err )
334425 }
@@ -337,12 +428,7 @@ func TestSetGetAuthFieldEncodedTextFile(t *testing.T) {
337428 }
338429}
339430
340- func deleteAuthFieldInKeyring (key authFieldKey ) error {
341- activeProfile , err := config .GetProfile ()
342- if err != nil {
343- return fmt .Errorf ("get profile: %w" , err )
344- }
345-
431+ func deleteAuthFieldInKeyring (activeProfile string , key authFieldKey ) error {
346432 if activeProfile != "" {
347433 activeProfileKeyring := filepath .Join (keyringService , activeProfile )
348434 return keyring .Delete (activeProfileKeyring , string (key ))
@@ -351,8 +437,8 @@ func deleteAuthFieldInKeyring(key authFieldKey) error {
351437 return keyring .Delete (keyringService , string (key ))
352438}
353439
354- func deleteAuthFieldInEncodedTextFile (key authFieldKey ) error {
355- err := createEncodedTextFile ()
440+ func deleteAuthFieldInEncodedTextFile (activeProfile string , key authFieldKey ) error {
441+ err := createEncodedTextFile (activeProfile )
356442 if err != nil {
357443 return err
358444 }
@@ -362,11 +448,6 @@ func deleteAuthFieldInEncodedTextFile(key authFieldKey) error {
362448 return fmt .Errorf ("get config dir: %w" , err )
363449 }
364450
365- activeProfile , err := config .GetProfile ()
366- if err != nil {
367- return fmt .Errorf ("get profile: %w" , err )
368- }
369-
370451 profileTextFileFolderName := textFileFolderName
371452 if activeProfile != "" {
372453 profileTextFileFolderName = filepath .Join (activeProfile , textFileFolderName )
0 commit comments