123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- package testing
- import (
- "strings"
- "testing"
- "devel.mephi.ru/iacherepanov/openstack-gophercloud"
- "devel.mephi.ru/iacherepanov/openstack-gophercloud/openstack"
- tokens2 "devel.mephi.ru/iacherepanov/openstack-gophercloud/openstack/identity/v2/tokens"
- tokens3 "devel.mephi.ru/iacherepanov/openstack-gophercloud/openstack/identity/v3/tokens"
- th "devel.mephi.ru/iacherepanov/openstack-gophercloud/testhelper"
- )
- // Service catalog fixtures take too much vertical space!
- var catalog2 = tokens2.ServiceCatalog{
- Entries: []tokens2.CatalogEntry{
- tokens2.CatalogEntry{
- Type: "same",
- Name: "same",
- Endpoints: []tokens2.Endpoint{
- tokens2.Endpoint{
- Region: "same",
- PublicURL: "https://public.correct.com/",
- InternalURL: "https://internal.correct.com/",
- AdminURL: "https://admin.correct.com/",
- },
- tokens2.Endpoint{
- Region: "different",
- PublicURL: "https://badregion.com/",
- },
- },
- },
- tokens2.CatalogEntry{
- Type: "same",
- Name: "different",
- Endpoints: []tokens2.Endpoint{
- tokens2.Endpoint{
- Region: "same",
- PublicURL: "https://badname.com/",
- },
- tokens2.Endpoint{
- Region: "different",
- PublicURL: "https://badname.com/+badregion",
- },
- },
- },
- tokens2.CatalogEntry{
- Type: "different",
- Name: "different",
- Endpoints: []tokens2.Endpoint{
- tokens2.Endpoint{
- Region: "same",
- PublicURL: "https://badtype.com/+badname",
- },
- tokens2.Endpoint{
- Region: "different",
- PublicURL: "https://badtype.com/+badregion+badname",
- },
- },
- },
- },
- }
- func TestV2EndpointExact(t *testing.T) {
- expectedURLs := map[gophercloud.Availability]string{
- gophercloud.AvailabilityPublic: "https://public.correct.com/",
- gophercloud.AvailabilityAdmin: "https://admin.correct.com/",
- gophercloud.AvailabilityInternal: "https://internal.correct.com/",
- }
- for availability, expected := range expectedURLs {
- actual, err := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{
- Type: "same",
- Name: "same",
- Region: "same",
- Availability: availability,
- })
- th.AssertNoErr(t, err)
- th.CheckEquals(t, expected, actual)
- }
- }
- func TestV2EndpointNone(t *testing.T) {
- _, actual := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{
- Type: "nope",
- Availability: gophercloud.AvailabilityPublic,
- })
- expected := &gophercloud.ErrEndpointNotFound{}
- th.CheckEquals(t, expected.Error(), actual.Error())
- }
- func TestV2EndpointMultiple(t *testing.T) {
- _, err := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{
- Type: "same",
- Region: "same",
- Availability: gophercloud.AvailabilityPublic,
- })
- if !strings.HasPrefix(err.Error(), "Discovered 2 matching endpoints:") {
- t.Errorf("Received unexpected error: %v", err)
- }
- }
- func TestV2EndpointBadAvailability(t *testing.T) {
- _, err := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{
- Type: "same",
- Name: "same",
- Region: "same",
- Availability: "wat",
- })
- th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error())
- }
- var catalog3 = tokens3.ServiceCatalog{
- Entries: []tokens3.CatalogEntry{
- tokens3.CatalogEntry{
- Type: "same",
- Name: "same",
- Endpoints: []tokens3.Endpoint{
- tokens3.Endpoint{
- ID: "1",
- Region: "same",
- Interface: "public",
- URL: "https://public.correct.com/",
- },
- tokens3.Endpoint{
- ID: "2",
- Region: "same",
- Interface: "admin",
- URL: "https://admin.correct.com/",
- },
- tokens3.Endpoint{
- ID: "3",
- Region: "same",
- Interface: "internal",
- URL: "https://internal.correct.com/",
- },
- tokens3.Endpoint{
- ID: "4",
- Region: "different",
- Interface: "public",
- URL: "https://badregion.com/",
- },
- },
- },
- tokens3.CatalogEntry{
- Type: "same",
- Name: "different",
- Endpoints: []tokens3.Endpoint{
- tokens3.Endpoint{
- ID: "5",
- Region: "same",
- Interface: "public",
- URL: "https://badname.com/",
- },
- tokens3.Endpoint{
- ID: "6",
- Region: "different",
- Interface: "public",
- URL: "https://badname.com/+badregion",
- },
- },
- },
- tokens3.CatalogEntry{
- Type: "different",
- Name: "different",
- Endpoints: []tokens3.Endpoint{
- tokens3.Endpoint{
- ID: "7",
- Region: "same",
- Interface: "public",
- URL: "https://badtype.com/+badname",
- },
- tokens3.Endpoint{
- ID: "8",
- Region: "different",
- Interface: "public",
- URL: "https://badtype.com/+badregion+badname",
- },
- },
- },
- tokens3.CatalogEntry{
- Type: "someother",
- Name: "someother",
- Endpoints: []tokens3.Endpoint{
- tokens3.Endpoint{
- ID: "1",
- Region: "someother",
- Interface: "public",
- URL: "https://public.correct.com/",
- },
- tokens3.Endpoint{
- ID: "2",
- RegionID: "someother",
- Interface: "admin",
- URL: "https://admin.correct.com/",
- },
- tokens3.Endpoint{
- ID: "3",
- RegionID: "someother",
- Interface: "internal",
- URL: "https://internal.correct.com/",
- },
- },
- },
- },
- }
- func TestV3EndpointExact(t *testing.T) {
- expectedURLs := map[gophercloud.Availability]string{
- gophercloud.AvailabilityPublic: "https://public.correct.com/",
- gophercloud.AvailabilityAdmin: "https://admin.correct.com/",
- gophercloud.AvailabilityInternal: "https://internal.correct.com/",
- }
- for availability, expected := range expectedURLs {
- actual, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
- Type: "same",
- Name: "same",
- Region: "same",
- Availability: availability,
- })
- th.AssertNoErr(t, err)
- th.CheckEquals(t, expected, actual)
- }
- }
- func TestV3EndpointNone(t *testing.T) {
- _, actual := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
- Type: "nope",
- Availability: gophercloud.AvailabilityPublic,
- })
- expected := &gophercloud.ErrEndpointNotFound{}
- th.CheckEquals(t, expected.Error(), actual.Error())
- }
- func TestV3EndpointMultiple(t *testing.T) {
- _, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
- Type: "same",
- Region: "same",
- Availability: gophercloud.AvailabilityPublic,
- })
- if !strings.HasPrefix(err.Error(), "Discovered 2 matching endpoints:") {
- t.Errorf("Received unexpected error: %v", err)
- }
- }
- func TestV3EndpointBadAvailability(t *testing.T) {
- _, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
- Type: "same",
- Name: "same",
- Region: "same",
- Availability: "wat",
- })
- th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error())
- }
- func TestV3EndpointWithRegionID(t *testing.T) {
- expectedURLs := map[gophercloud.Availability]string{
- gophercloud.AvailabilityPublic: "https://public.correct.com/",
- gophercloud.AvailabilityAdmin: "https://admin.correct.com/",
- gophercloud.AvailabilityInternal: "https://internal.correct.com/",
- }
- for availability, expected := range expectedURLs {
- actual, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
- Type: "someother",
- Name: "someother",
- Region: "someother",
- Availability: availability,
- })
- th.AssertNoErr(t, err)
- th.CheckEquals(t, expected, actual)
- }
- }
|