blob: 60c71c889fb3577a001d01ec5602d4c1dfa25866 [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 II0167aaa2013-07-16 12:36:25 -070023func (ta *testAccess) Revoke(string) error {
24 return nil
25}
26
Samuel A. Falvo II9e64f6b2013-07-16 14:26:50 -070027func (ta *testAccess) Reauthenticate() error {
28 return nil
29}
30
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070031func TestGetServersApi(t *testing.T) {
32 c := TestContext().UseCustomClient(&http.Client{Transport: newTransport().WithResponse("Hello")})
33
34 acc := &testAccess{
35 public: "http://localhost:8080",
36 internal: "http://localhost:8086",
37 }
38
Samuel A. Falvo II1dd740a2013-07-08 15:48:40 -070039 _, err := c.ServersApi(acc, ApiCriteria{
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070040 Name: "cloudComputeOpenStack",
41 Region: "dfw",
42 VersionId: "2",
43 })
44
45 if err != nil {
46 t.Error(err)
47 return
48 }
49
50 if acc.calledFirstEndpointByCriteria != 1 {
51 t.Error("Expected FirstEndpointByCriteria to be called")
52 return
53 }
54}