Ash Wilson | fc1af5a | 2014-10-08 09:10:41 -0400 | [diff] [blame^] | 1 | package openstack |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/rackspace/gophercloud" |
| 8 | tokens2 "github.com/rackspace/gophercloud/openstack/identity/v2/tokens" |
| 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | ) |
| 11 | |
| 12 | // Service catalog fixtures take too much vertical space! |
| 13 | var catalog2 = tokens2.ServiceCatalog{ |
| 14 | Entries: []tokens2.CatalogEntry{ |
| 15 | tokens2.CatalogEntry{ |
| 16 | Type: "same", |
| 17 | Name: "same", |
| 18 | Endpoints: []tokens2.Endpoint{ |
| 19 | tokens2.Endpoint{ |
| 20 | Region: "same", |
| 21 | PublicURL: "https://public.correct.com/", |
| 22 | InternalURL: "https://internal.correct.com/", |
| 23 | AdminURL: "https://admin.correct.com/", |
| 24 | }, |
| 25 | tokens2.Endpoint{ |
| 26 | Region: "different", |
| 27 | PublicURL: "https://badregion.com/", |
| 28 | }, |
| 29 | }, |
| 30 | }, |
| 31 | tokens2.CatalogEntry{ |
| 32 | Type: "same", |
| 33 | Name: "different", |
| 34 | Endpoints: []tokens2.Endpoint{ |
| 35 | tokens2.Endpoint{ |
| 36 | Region: "same", |
| 37 | PublicURL: "https://badname.com/", |
| 38 | }, |
| 39 | tokens2.Endpoint{ |
| 40 | Region: "different", |
| 41 | PublicURL: "https://badname.com/+badregion", |
| 42 | }, |
| 43 | }, |
| 44 | }, |
| 45 | tokens2.CatalogEntry{ |
| 46 | Type: "different", |
| 47 | Name: "different", |
| 48 | Endpoints: []tokens2.Endpoint{ |
| 49 | tokens2.Endpoint{ |
| 50 | Region: "same", |
| 51 | PublicURL: "https://badtype.com/+badname", |
| 52 | }, |
| 53 | tokens2.Endpoint{ |
| 54 | Region: "different", |
| 55 | PublicURL: "https://badtype.com/+badregion+badname", |
| 56 | }, |
| 57 | }, |
| 58 | }, |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | func TestV2EndpointExact(t *testing.T) { |
| 63 | expectedURLs := map[gophercloud.Availability]string{ |
| 64 | gophercloud.AvailabilityPublic: "https://public.correct.com/", |
| 65 | gophercloud.AvailabilityAdmin: "https://admin.correct.com/", |
| 66 | gophercloud.AvailabilityInternal: "https://internal.correct.com/", |
| 67 | } |
| 68 | |
| 69 | for availability, expected := range expectedURLs { |
| 70 | actual, err := V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ |
| 71 | Type: "same", |
| 72 | Name: "same", |
| 73 | Region: "same", |
| 74 | Availability: availability, |
| 75 | }) |
| 76 | th.AssertNoErr(t, err) |
| 77 | th.CheckEquals(t, expected, actual) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func TestV2EndpointNone(t *testing.T) { |
| 82 | _, err := V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ |
| 83 | Type: "nope", |
| 84 | Availability: gophercloud.AvailabilityPublic, |
| 85 | }) |
| 86 | th.CheckEquals(t, gophercloud.ErrEndpointNotFound, err) |
| 87 | } |
| 88 | |
| 89 | func TestV2EndpointMultiple(t *testing.T) { |
| 90 | _, err := V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ |
| 91 | Type: "same", |
| 92 | Region: "same", |
| 93 | Availability: gophercloud.AvailabilityPublic, |
| 94 | }) |
| 95 | if !strings.HasPrefix(err.Error(), "Discovered 2 matching endpoints:") { |
| 96 | t.Errorf("Received unexpected error: %v", err) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | func TestV2EndpointBadAvailability(t *testing.T) { |
| 101 | _, err := V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ |
| 102 | Type: "same", |
| 103 | Name: "same", |
| 104 | Region: "same", |
| 105 | Availability: "wat", |
| 106 | }) |
| 107 | th.CheckEquals(t, err.Error(), "Unexpected availability in endpoint query: wat") |
| 108 | } |