(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestFromConfig(t *testing.T) { |
| 27 | newString := func(s string) *string { |
| 28 | return &s |
| 29 | } |
| 30 | tests := []struct { |
| 31 | in string |
| 32 | |
| 33 | want interface{} |
| 34 | wanterr interface{} |
| 35 | }{ |
| 36 | {in: "", wanterr: ErrNoAuth}, |
| 37 | {in: "slkdjflksdjf", wanterr: `Unknown auth type: "slkdjflksdjf"`}, |
| 38 | {in: "none", want: None{}}, |
| 39 | {in: "localhost", want: Localhost{}}, |
| 40 | {in: "userpass:alice:secret", want: &UserPass{Username: "alice", Password: "secret", OrLocalhost: false, VivifyPass: nil}}, |
| 41 | {in: "userpass:alice:secret:+localhost", want: &UserPass{Username: "alice", Password: "secret", OrLocalhost: true, VivifyPass: nil}}, |
| 42 | {in: "userpass:alice:secret:+localhost:vivify=foo", want: &UserPass{Username: "alice", Password: "secret", OrLocalhost: true, VivifyPass: newString("foo")}}, |
| 43 | {in: "devauth:port3179", want: &DevAuth{Password: "port3179", VivifyPass: newString("viviport3179")}}, |
| 44 | {in: "basic:alice:secret", want: &UserPass{Username: "alice", Password: "secret", OrLocalhost: false, VivifyPass: nil}}, |
| 45 | {in: "basic:alice:secret:+localhost", wanterr: `invalid basic auth syntax. got "alice:secret:+localhost", want "username:password"`}, |
| 46 | {in: "basic:alice:secret:+vivify=foo", wanterr: `invalid basic auth syntax. got "alice:secret:+vivify=foo", want "username:password"`}, |
| 47 | } |
| 48 | for _, tt := range tests { |
| 49 | am, err := FromConfig(tt.in) |
| 50 | if err != nil || tt.wanterr != nil { |
| 51 | if fmt.Sprint(err) != fmt.Sprint(tt.wanterr) { |
| 52 | t.Errorf("FromConfig(%q) = error %v; want %v", tt.in, err, tt.wanterr) |
| 53 | } |
| 54 | continue |
| 55 | } |
| 56 | if !reflect.DeepEqual(am, tt.want) { |
| 57 | t.Errorf("FromConfig(%q) = %#v; want %#v", tt.in, am, tt.want) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestMultiMode(t *testing.T) { |
| 63 | req, err := http.NewRequest("GET", "/", nil) |
nothing calls this directly
no test coverage detected