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 | |
| 19 | func TestGetServersApi(t *testing.T) { |
| 20 | c := TestContext().UseCustomClient(&http.Client{Transport: newTransport().WithResponse("Hello")}) |
| 21 | |
| 22 | acc := &testAccess{ |
| 23 | public: "http://localhost:8080", |
| 24 | internal: "http://localhost:8086", |
| 25 | } |
| 26 | |
| 27 | _, err := c.ComputeApi(acc, ApiCriteria{ |
| 28 | Name: "cloudComputeOpenStack", |
| 29 | Region: "dfw", |
| 30 | VersionId: "2", |
| 31 | }) |
| 32 | |
| 33 | if err != nil { |
| 34 | t.Error(err) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | if acc.calledFirstEndpointByCriteria != 1 { |
| 39 | t.Error("Expected FirstEndpointByCriteria to be called") |
| 40 | return |
| 41 | } |
| 42 | } |