-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreader_test.go
43 lines (38 loc) · 939 Bytes
/
reader_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pgpass
import (
"bytes"
"testing"
)
func TestEntryReader(t *testing.T) {
data := bytes.NewBufferString(
`host:5432:db:root:god123
# Comment line
host:5432:db:root:god\:123
host:5432:db:root:
host:5432::root:god 123
*:*:*:root:god123
host:5432:db:ro\:ot:god123
host:5432:db:root\\:god123
`)
expected := []Entry{
Entry{"host", "5432", "db", "root", "god123"},
Entry{"host", "5432", "db", "root", "god:123"},
Entry{"host", "5432", "db", "root", ""},
Entry{"host", "5432", "", "root", "god 123"},
Entry{"*", "*", "*", "root", "god123"},
Entry{"host", "5432", "db", "ro:ot", "god123"},
Entry{"host", "5432", "db", `root\`, "god123"},
}
r := NewEntryReader(data)
for n, exp := range expected {
if !r.Next() {
t.Fatalf("No more entries (%d): %s", n, r.Err())
}
if e := r.Entry(); e != exp {
t.Errorf("%d: expected %v, got %v", n, exp, e)
}
}
if err := r.Err(); err != nil {
t.Error(err)
}
}