comparison file/file_test.go @ 18:00d30c67b56d

Put all the library stuff into multipass/file.
author Paul Fisher <paul@pfish.zone>
date Sun, 01 Nov 2015 12:16:51 -0500
parents bfc035bd5132
children
comparison
equal deleted inserted replaced
17:342f63116bfd 18:00d30c67b56d
5 "io/ioutil" 5 "io/ioutil"
6 "os" 6 "os"
7 "path" 7 "path"
8 "testing" 8 "testing"
9 "time" 9 "time"
10
11 "pfish.zone/go/multipass/auth"
12 ) 10 )
13 11
14 var tempdir string 12 var tempdir string
15 13
16 const ( 14 const (
19 shadowSpooky = "123:bogushash:c3Bvb2t5" 17 shadowSpooky = "123:bogushash:c3Bvb2t5"
20 shadowWhatever = "456:anotherhash:d2hhdGV2ZXI=" 18 shadowWhatever = "456:anotherhash:d2hhdGV2ZXI="
21 ) 19 )
22 20
23 var ( 21 var (
24 aSpooky *auth.Entry 22 aSpooky *Entry
25 aWhatever *auth.Entry 23 aWhatever *Entry
26 ) 24 )
27 25
28 func init() { 26 func init() {
29 s, err := auth.EntryFromShadow(shadowSpooky) 27 s, err := EntryFromShadow(shadowSpooky)
30 if err != nil { 28 if err != nil {
31 panic(err.Error()) 29 panic(err.Error())
32 } 30 }
33 aSpooky = s 31 aSpooky = s
34 w, err := auth.EntryFromShadow(shadowWhatever) 32 w, err := EntryFromShadow(shadowWhatever)
35 if err != nil { 33 if err != nil {
36 panic(err.Error()) 34 panic(err.Error())
37 } 35 }
38 aWhatever = w 36 aWhatever = w
39 } 37 }
186 if *entries[0] != *aWhatever || *entries[1] != *aSpooky { 184 if *entries[0] != *aWhatever || *entries[1] != *aSpooky {
187 t.Fatalf("want {aWhatever, aSpooky}; got %d", entries) 185 t.Fatalf("want {aWhatever, aSpooky}; got %d", entries)
188 } 186 }
189 } 187 }
190 188
191 func TestAuthenticate(t *testing.T) { 189 func TestAuthenticateFile(t *testing.T) {
192 f := mktest(t, "auth") 190 f := mktest(t, "auth")
193 defer f.cleanup() 191 defer f.cleanup()
194 s := New(f.filepath()) 192 s := New(f.filepath())
195 eA, passA, err := auth.NewEntry("a") 193 eA, passA, err := NewEntry("a")
196 if err != nil { 194 if err != nil {
197 t.Fatalf(err.Error()) 195 t.Fatalf(err.Error())
198 } 196 }
199 eB, passB, err := auth.NewEntry("b") 197 eB, passB, err := NewEntry("b")
200 if err != nil { 198 if err != nil {
201 t.Fatalf(err.Error()) 199 t.Fatalf(err.Error())
202 } 200 }
203 err = s.Add(eA) 201 err = s.Add(eA)
204 if err != nil { 202 if err != nil {