Samuel A. Falvo II | fd78c30 | 2013-06-25 16:35:32 -0700 | [diff] [blame^] | 1 | package gophercloud |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | func TestAuthProvider(t *testing.T) { |
| 8 | c := TestContext() |
| 9 | |
| 10 | _, err := c.Authenticate("", AuthOptions{}) |
| 11 | if err == nil { |
| 12 | t.Error("Expected error for empty provider string") |
| 13 | return |
| 14 | } |
| 15 | _, err = c.Authenticate("unknown-provider", AuthOptions{Username: "u", Password: "p"}) |
| 16 | if err == nil { |
| 17 | t.Error("Expected error for unknown service provider") |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | err = c.RegisterProvider("provider", &Provider{}) |
| 22 | if err != nil { |
| 23 | t.Error(err) |
| 24 | return |
| 25 | } |
| 26 | _, err = c.Authenticate("provider", AuthOptions{Username: "u", Password: "p"}) |
| 27 | if err != nil { |
| 28 | t.Error(err) |
| 29 | return |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestUserNameAndPassword(t *testing.T) { |
| 34 | c := TestContext() |
| 35 | c.RegisterProvider("provider", &Provider{}) |
| 36 | |
| 37 | auths := []AuthOptions{ |
| 38 | AuthOptions{}, |
| 39 | AuthOptions{Username: "u"}, |
| 40 | AuthOptions{Password: "p"}, |
| 41 | } |
| 42 | for i, auth := range auths { |
| 43 | _, err := c.Authenticate("provider", auth) |
| 44 | if err == nil { |
| 45 | t.Error("Expected error from missing credentials (%d)", i) |
| 46 | return |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | _, err := c.Authenticate("provider", AuthOptions{Username: "u", Password: "p"}) |
| 51 | if err != nil { |
| 52 | t.Error(err) |
| 53 | return |
| 54 | } |
| 55 | } |