forked from fhs/go-netrc
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't serialize tokens with no values.
Fixes #3.
- Loading branch information
Showing
2 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,15 @@ package netrc | |
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var expectedMachines = []*Machine{ | ||
&Machine{Name: "mail.google.com", Login: "[email protected]", Password: "somethingSecret", Account: "gmail"}, | ||
&Machine{Name: "mail.google.com", Login: "[email protected]", Password: "somethingSecret", Account: "justagmail"}, | ||
&Machine{Name: "ray", Login: "demo", Password: "mypassword", Account: ""}, | ||
&Machine{Name: "weirdlogin", Login: "uname", Password: "pass#pass", Account: ""}, | ||
&Machine{Name: "", Login: "anonymous", Password: "[email protected]", Account: ""}, | ||
|
@@ -185,6 +186,18 @@ func TestMarshalText(t *testing.T) { | |
if string(result) != string(expected) { | ||
t.Errorf("expected:\n%q\ngot:\n%q", string(expected), string(result)) | ||
} | ||
|
||
// make sure tokens w/ no value are not serialized | ||
m := n.FindMachine("mail.google.com") | ||
m.UpdatePassword("") | ||
result, err = n.MarshalText() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if strings.Contains(string(result), "\tpassword \n") { | ||
fmt.Println(string(result)) | ||
t.Errorf("expected zero-value password token to not be serialzed") | ||
} | ||
} | ||
|
||
var newMachineTests = []struct { | ||
|