diff options
| author | Felix Hanley <felix@userspace.com.au> | 2017-06-11 13:25:57 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2017-06-11 13:29:15 +0000 |
| commit | 3185a43420dab2efb85aa601bdfe267e8b2e11f2 (patch) | |
| tree | 846c21d92f7089e3e43c2fec3dbee90aef938f9b /vendor/github.com/jackc/pgx/pgpass_test.go | |
| parent | 3291eddb975a1df77975d8083599b5f3a85afaba (diff) | |
| download | dhtsearch-3185a43420dab2efb85aa601bdfe267e8b2e11f2.tar.gz dhtsearch-3185a43420dab2efb85aa601bdfe267e8b2e11f2.tar.bz2 | |
Add torrent tagging
- Move to postgresql to reduce locking issues
- Move ih hash to single thread
- Clean up stuff
Diffstat (limited to 'vendor/github.com/jackc/pgx/pgpass_test.go')
| -rw-r--r-- | vendor/github.com/jackc/pgx/pgpass_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/github.com/jackc/pgx/pgpass_test.go b/vendor/github.com/jackc/pgx/pgpass_test.go new file mode 100644 index 0000000..f6094c8 --- /dev/null +++ b/vendor/github.com/jackc/pgx/pgpass_test.go @@ -0,0 +1,57 @@ +package pgx + +import ( + "fmt" + "io/ioutil" + "os" + "strings" + "testing" +) + +func unescape(s string) string { + s = strings.Replace(s, `\:`, `:`, -1) + s = strings.Replace(s, `\\`, `\`, -1) + return s +} + +var passfile = [][]string{ + []string{"test1", "5432", "larrydb", "larry", "whatstheidea"}, + []string{"test1", "5432", "moedb", "moe", "imbecile"}, + []string{"test1", "5432", "curlydb", "curly", "nyuknyuknyuk"}, + []string{"test2", "5432", "*", "shemp", "heymoe"}, + []string{"test2", "5432", "*", "*", `test\\ing\:`}, +} + +func TestPGPass(t *testing.T) { + tf, err := ioutil.TempFile("", "") + if err != nil { + t.Fatal(err) + } + defer tf.Close() + defer os.Remove(tf.Name()) + os.Setenv("PGPASSFILE", tf.Name()) + for _, l := range passfile { + _, err := fmt.Fprintln(tf, strings.Join(l, `:`)) + if err != nil { + t.Fatal(err) + } + } + if err = tf.Close(); err != nil { + t.Fatal(err) + } + for i, l := range passfile { + cfg := ConnConfig{Host: l[0], Database: l[2], User: l[3]} + found := pgpass(&cfg) + if !found { + t.Fatalf("Entry %v not found", i) + } + if cfg.Password != unescape(l[4]) { + t.Fatalf(`Password mismatch entry %v want %s got %s`, i, unescape(l[4]), cfg.Password) + } + } + cfg := ConnConfig{Host: "derp", Database: "herp", User: "joe"} + found := pgpass(&cfg) + if found { + t.Fatal("bad found") + } +} |
