github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/testing/endpoint_location_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/openstack" 8 tokens3 "github.com/opentelekomcloud/gophertelekomcloud/openstack/identity/v3/tokens" 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 ) 11 12 var catalog3 = tokens3.ServiceCatalog{ 13 Entries: []tokens3.CatalogEntry{ 14 { 15 Type: "same", 16 Name: "same", 17 Endpoints: []tokens3.Endpoint{ 18 { 19 ID: "1", 20 Region: "same", 21 Interface: "public", 22 URL: "https://public.correct.com/", 23 }, 24 { 25 ID: "2", 26 Region: "same", 27 Interface: "admin", 28 URL: "https://admin.correct.com/", 29 }, 30 { 31 ID: "3", 32 Region: "same", 33 Interface: "internal", 34 URL: "https://internal.correct.com/", 35 }, 36 { 37 ID: "4", 38 Region: "different", 39 Interface: "public", 40 URL: "https://badregion.com/", 41 }, 42 }, 43 }, 44 { 45 Type: "same", 46 Name: "different", 47 Endpoints: []tokens3.Endpoint{ 48 { 49 ID: "5", 50 Region: "same", 51 Interface: "public", 52 URL: "https://badname.com/", 53 }, 54 { 55 ID: "6", 56 Region: "different", 57 Interface: "public", 58 URL: "https://badname.com/+badregion", 59 }, 60 }, 61 }, 62 { 63 Type: "different", 64 Name: "different", 65 Endpoints: []tokens3.Endpoint{ 66 { 67 ID: "7", 68 Region: "same", 69 Interface: "public", 70 URL: "https://badtype.com/+badname", 71 }, 72 { 73 ID: "8", 74 Region: "different", 75 Interface: "public", 76 URL: "https://badtype.com/+badregion+badname", 77 }, 78 }, 79 }, 80 }, 81 } 82 83 func TestV3EndpointExact(t *testing.T) { 84 expectedURLs := map[golangsdk.Availability]string{ 85 golangsdk.AvailabilityPublic: "https://public.correct.com/", 86 golangsdk.AvailabilityAdmin: "https://admin.correct.com/", 87 golangsdk.AvailabilityInternal: "https://internal.correct.com/", 88 } 89 90 for availability, expected := range expectedURLs { 91 actual, err := openstack.V3EndpointURL(&catalog3, golangsdk.EndpointOpts{ 92 Type: "same", 93 Name: "same", 94 Region: "same", 95 Availability: availability, 96 }) 97 th.AssertNoErr(t, err) 98 th.CheckEquals(t, expected, actual) 99 } 100 } 101 102 func TestV3EndpointNone(t *testing.T) { 103 _, actual := openstack.V3EndpointURL(&catalog3, golangsdk.EndpointOpts{ 104 Type: "nope", 105 Availability: golangsdk.AvailabilityPublic, 106 }) 107 expected := &golangsdk.ErrEndpointNotFound{} 108 if actual == nil { 109 t.Fatalf("Expected error") 110 } 111 th.CheckEquals(t, expected.Error(), actual.Error()) 112 } 113 114 func TestV3EndpointBadAvailability(t *testing.T) { 115 _, err := openstack.V3EndpointURL(&catalog3, golangsdk.EndpointOpts{ 116 Type: "same", 117 Name: "same", 118 Region: "same", 119 Availability: "wat", 120 }) 121 if err == nil { 122 t.Fatalf("Expected error") 123 } 124 th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error()) 125 }