| Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 1 | package gophercloud | 
|  | 2 |  | 
|  | 3 | import ( | 
|  | 4 | "net/http" | 
|  | 5 | "testing" | 
|  | 6 | ) | 
|  | 7 |  | 
|  | 8 | type testAccess struct { | 
|  | 9 | public, internal              string | 
|  | 10 | calledFirstEndpointByCriteria int | 
|  | 11 | } | 
|  | 12 |  | 
|  | 13 | func (ta *testAccess) FirstEndpointUrlByCriteria(ac ApiCriteria) string { | 
|  | 14 | ta.calledFirstEndpointByCriteria++ | 
|  | 15 | urls := []string{ta.public, ta.internal} | 
|  | 16 | return urls[ac.UrlChoice] | 
|  | 17 | } | 
|  | 18 |  | 
| Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 19 | func (ta *testAccess) AuthToken() string { | 
|  | 20 | return "" | 
|  | 21 | } | 
|  | 22 |  | 
| Samuel A. Falvo II | 0167aaa | 2013-07-16 12:36:25 -0700 | [diff] [blame^] | 23 | func (ta *testAccess) Revoke(string) error { | 
|  | 24 | return nil | 
|  | 25 | } | 
|  | 26 |  | 
| Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 27 | func TestGetServersApi(t *testing.T) { | 
|  | 28 | c := TestContext().UseCustomClient(&http.Client{Transport: newTransport().WithResponse("Hello")}) | 
|  | 29 |  | 
|  | 30 | acc := &testAccess{ | 
|  | 31 | public:   "http://localhost:8080", | 
|  | 32 | internal: "http://localhost:8086", | 
|  | 33 | } | 
|  | 34 |  | 
| Samuel A. Falvo II | 1dd740a | 2013-07-08 15:48:40 -0700 | [diff] [blame] | 35 | _, err := c.ServersApi(acc, ApiCriteria{ | 
| Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 36 | Name:      "cloudComputeOpenStack", | 
|  | 37 | Region:    "dfw", | 
|  | 38 | VersionId: "2", | 
|  | 39 | }) | 
|  | 40 |  | 
|  | 41 | if err != nil { | 
|  | 42 | t.Error(err) | 
|  | 43 | return | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | if acc.calledFirstEndpointByCriteria != 1 { | 
|  | 47 | t.Error("Expected FirstEndpointByCriteria to be called") | 
|  | 48 | return | 
|  | 49 | } | 
|  | 50 | } |