blob: 46ba6dbe5b5673aa97457863e4c8cabc9cbf6f81 [file] [log] [blame]
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -07001package gophercloud
2
3import (
4 "net/http"
5 "testing"
6)
7
8type testAccess struct {
9 public, internal string
10 calledFirstEndpointByCriteria int
11}
12
13func (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 IIbc0d54a2013-07-08 14:45:21 -070019func (ta *testAccess) AuthToken() string {
20 return ""
21}
22
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070023func TestGetServersApi(t *testing.T) {
24 c := TestContext().UseCustomClient(&http.Client{Transport: newTransport().WithResponse("Hello")})
25
26 acc := &testAccess{
27 public: "http://localhost:8080",
28 internal: "http://localhost:8086",
29 }
30
Samuel A. Falvo II1dd740a2013-07-08 15:48:40 -070031 _, err := c.ServersApi(acc, ApiCriteria{
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070032 Name: "cloudComputeOpenStack",
33 Region: "dfw",
34 VersionId: "2",
35 })
36
37 if err != nil {
38 t.Error(err)
39 return
40 }
41
42 if acc.calledFirstEndpointByCriteria != 1 {
43 t.Error("Expected FirstEndpointByCriteria to be called")
44 return
45 }
46}