@@ -17,6 +17,7 @@ import (
1717var  expectedMachines  =  []* Machine {
1818	& Machine {
Name : 
"mail.google.com" , 
Login : 
"[email protected] " , 
Password : 
"somethingSecret" , 
Account : 
"justagmail" },
 1919	& Machine {Name : "ray" , Login : "demo" , Password : "mypassword" , Account : "" },
20+ 	& Machine {Name : "ray" , Login : "demo1" , Password : "demo1_password" , Account : "" },
2021	& Machine {Name : "weirdlogin" , Login : "uname" , Password : "pass#pass" , Account : "" },
2122	& Machine {
Name : 
"google.com" , 
Login : 
"[email protected] " , 
Password : 
"secure" },
 2223	& Machine {
Name : 
"" , 
Login : 
"anonymous" , 
Password : 
"[email protected] " , 
Account : 
"" },
 @@ -132,7 +133,7 @@ func TestParseFile(t *testing.T) {
132133}
133134
134135func  TestFindMachine (t  * testing.T ) {
135- 	m , err  :=  FindMachine ("examples/good.netrc" , "ray" )
136+ 	m , err  :=  FindMachine ("examples/good.netrc" , "ray" ,  "" )
136137	if  err  !=  nil  {
137138		t .Fatal (err )
138139	}
@@ -143,12 +144,34 @@ func TestFindMachine(t *testing.T) {
143144		t .Errorf ("expected m.IsDefault() to be false" )
144145	}
145146
146- 	m , err  =  FindMachine ("examples/good.netrc" , "non.existent " )
147+ 	m , err  =  FindMachine ("examples/good.netrc" , "ray"  ,  "demo1 " )
147148	if  err  !=  nil  {
148149		t .Fatal (err )
149150	}
150- 	if  ! eqMachine (m , expectedMachines [4 ]) {
151- 		t .Errorf ("bad machine; expected %v, got %v\n " , expectedMachines [3 ], m )
151+ 	if  ! eqMachine (m , expectedMachines [2 ]) {
152+ 		t .Errorf ("bad machine; expected %v, got %v\n " , expectedMachines [2 ], m )
153+ 	}
154+ 	if  m .IsDefault () {
155+ 		t .Errorf ("expected m.IsDefault() to be false" )
156+ 	}
157+ 
158+ 	m , err  =  FindMachine ("examples/good.netrc" , "ray" , "non.existent" )
159+ 	if  err  !=  nil  {
160+ 		t .Fatal (err )
161+ 	}
162+ 	if  ! eqMachine (m , expectedMachines [5 ]) {
163+ 		t .Errorf ("bad machine; expected %v, got %v\n " , expectedMachines [5 ], m )
164+ 	}
165+ 	if  ! m .IsDefault () {
166+ 		t .Errorf ("expected m.IsDefault() to be true" )
167+ 	}
168+ 
169+ 	m , err  =  FindMachine ("examples/good.netrc" , "non.existent" , "" )
170+ 	if  err  !=  nil  {
171+ 		t .Fatal (err )
172+ 	}
173+ 	if  ! eqMachine (m , expectedMachines [5 ]) {
174+ 		t .Errorf ("bad machine; expected %v, got %v\n " , expectedMachines [5 ], m )
152175	}
153176	if  ! m .IsDefault () {
154177		t .Errorf ("expected m.IsDefault() to be true" )
@@ -161,7 +184,7 @@ func TestNetrcFindMachine(t *testing.T) {
161184		t .Fatal (err )
162185	}
163186
164- 	m  :=  n .FindMachine ("ray" )
187+ 	m  :=  n .FindMachine ("ray" ,  "" )
165188	if  ! eqMachine (m , expectedMachines [1 ]) {
166189		t .Errorf ("bad machine; expected %v, got %v\n " , expectedMachines [1 ], m )
167190	}
@@ -170,7 +193,7 @@ func TestNetrcFindMachine(t *testing.T) {
170193	}
171194
172195	n  =  & Netrc {}
173- 	m  =  n .FindMachine ("nonexistent" )
196+ 	m  =  n .FindMachine ("nonexistent" ,  "" )
174197	if  m  !=  nil  {
175198		t .Errorf ("expected nil, got %v" , m )
176199	}
@@ -197,7 +220,7 @@ func TestMarshalText(t *testing.T) {
197220	}
198221
199222	// make sure tokens w/ no value are not serialized 
200- 	m  :=  n .FindMachine ("mail.google.com" )
223+ 	m  :=  n .FindMachine ("mail.google.com" ,  "" )
201224	m .UpdatePassword ("" )
202225	result , err  =  n .MarshalText ()
203226	if  err  !=  nil  {
@@ -359,26 +382,34 @@ func TestRemoveMachine(t *testing.T) {
359382		t .Fatal (err )
360383	}
361384
362- 	tests  :=  []string {"mail.google.com" , "weirdlogin" }
385+ 	tests  :=  []struct  {
386+                 name   string 
387+                 login  string 
388+         }{
389+                 {"mail.google.com" , "" },
390+                 {"weirdlogin" , "uname" },
391+         }
363392
364- 	for  _ , name  :=  range  tests  {
393+ 	for  _ , test  :=  range  tests  {
394+ 		name  :=  test .name 
395+ 		loginName  :=  test .login 
365396		mcount  :=  len (n .machines )
366397		// sanity check 
367- 		m  :=  n .FindMachine (name )
398+ 		m  :=  n .FindMachine (name ,  loginName )
368399		if  m  ==  nil  {
369400			t .Fatalf ("machine %q not found" , name )
370401		}
371402		if  m .IsDefault () {
372403			t .Fatalf ("expected machine %q, got default instead" , name )
373404		}
374- 		n .RemoveMachine (name )
405+ 		n .RemoveMachine (name ,  loginName )
375406
376407		if  len (n .machines ) !=  mcount - 1  {
377408			t .Errorf ("n.machines count expected %d, got %d" , mcount - 1 , len (n .machines ))
378409		}
379410
380411		// make sure Machine is no longer returned by FindMachine() 
381- 		if  m2  :=  n .FindMachine (name ); m2  !=  nil  &&  ! m2 .IsDefault () {
412+ 		if  m2  :=  n .FindMachine (name ,  loginName ); m2  !=  nil  &&  ! m2 .IsDefault () {
382413			t .Errorf ("Machine %q not removed from Machines list" , name )
383414		}
384415
@@ -429,7 +460,7 @@ func TestUpdateLogin(t *testing.T) {
429460	}
430461
431462	for  _ , test  :=  range  tests  {
432- 		m  :=  n .FindMachine (test .name )
463+ 		m  :=  n .FindMachine (test .name ,  "" )
433464		if  m .IsDefault () ==  test .exists  {
434465			t .Errorf ("expected machine %s to not exist, but it did" , test .name )
435466		} else  {
@@ -441,7 +472,7 @@ func TestUpdateLogin(t *testing.T) {
441472				continue 
442473			}
443474			m .UpdateLogin (test .newlogin )
444- 			m  :=  n .FindMachine (test .name )
475+ 			m  :=  n .FindMachine (test .name ,  "" )
445476			if  m .Login  !=  test .newlogin  {
446477				t .Errorf ("expected new login %q, got %q" , test .newlogin , m .Login )
447478			}
@@ -491,7 +522,7 @@ func TestUpdatePassword(t *testing.T) {
491522	}
492523
493524	for  _ , test  :=  range  tests  {
494- 		m  :=  n .FindMachine (test .name )
525+ 		m  :=  n .FindMachine (test .name ,  "" )
495526		if  m .IsDefault () ==  test .exists  {
496527			t .Errorf ("expected machine %s to not exist, but it did" , test .name )
497528		} else  {
@@ -503,7 +534,7 @@ func TestUpdatePassword(t *testing.T) {
503534				continue 
504535			}
505536			m .UpdatePassword (test .newpassword )
506- 			m  =  n .FindMachine (test .name )
537+ 			m  =  n .FindMachine (test .name ,  "" )
507538			if  m .Password  !=  test .newpassword  {
508539				t .Errorf ("expected new password %q, got %q" , test .newpassword , m .Password )
509540			}
0 commit comments