Samuel A. Falvo II | 8a549ef | 2014-01-24 15:20:54 -0800 | [diff] [blame] | 1 | package identity |
| 2 | |
| 3 | import ( |
Samuel A. Falvo II | 8a549ef | 2014-01-24 15:20:54 -0800 | [diff] [blame] | 4 | "encoding/json" |
Samuel A. Falvo II | 0262e97 | 2014-01-24 16:06:56 -0800 | [diff] [blame] | 5 | "testing" |
Samuel A. Falvo II | 8a549ef | 2014-01-24 15:20:54 -0800 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | func TestServiceCatalog(t *testing.T) { |
| 9 | authResults := make(map[string]interface{}) |
| 10 | err := json.Unmarshal([]byte(authResultsOK), &authResults) |
| 11 | if err != nil { |
| 12 | t.Error(err) |
| 13 | return |
| 14 | } |
| 15 | |
| 16 | sc, err := ServiceCatalog(authResults) |
| 17 | if err != nil { |
| 18 | panic(err) |
| 19 | } |
| 20 | |
| 21 | if sc.NumberOfServices() != 3 { |
| 22 | t.Errorf("Expected 3 services; got %d", sc.NumberOfServices()) |
| 23 | } |
| 24 | |
| 25 | ces, err := sc.CatalogEntries() |
| 26 | if err != nil { |
| 27 | t.Error(err) |
| 28 | return |
| 29 | } |
| 30 | for _, ce := range ces { |
| 31 | if strNotInStrList(ce.Name, "Cloud Servers", "Cloud Files", "DNS-as-a-Service") { |
| 32 | t.Errorf("Expected \"%s\" to be one of Cloud Servers, Cloud Files, or DNS-as-a-Service", ce.Name) |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | if strNotInStrList(ce.Type, "dnsextension:dns", "object-store", "compute") { |
| 37 | t.Errorf("Expected \"%s\" to be one of dnsextension:dns, object-store, or compute") |
| 38 | return |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | eps := endpointsFor(ces, "compute") |
| 43 | if len(eps) != 2 { |
| 44 | t.Errorf("Expected 2 endpoints for compute service") |
| 45 | return |
| 46 | } |
| 47 | for _, ep := range eps { |
| 48 | if strNotInStrList(ep.VersionId, "1", "1.1", "1.1") { |
| 49 | t.Errorf("Expected versionId field of compute resource to be one of 1 or 1.1") |
| 50 | return |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | eps = endpointsFor(ces, "object-store") |
| 55 | if len(eps) != 2 { |
| 56 | t.Errorf("Expected 2 endpoints for object-store service") |
| 57 | return |
| 58 | } |
| 59 | for _, ep := range eps { |
| 60 | if ep.VersionId != "1" { |
| 61 | t.Errorf("Expected only version 1 object store API version") |
| 62 | return |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | eps = endpointsFor(ces, "dnsextension:dns") |
| 67 | if len(eps) != 1 { |
| 68 | t.Errorf("Expected 1 endpoint for DNS-as-a-Service service") |
| 69 | return |
| 70 | } |
| 71 | if eps[0].VersionId != "2.0" { |
| 72 | t.Errorf("Expected version 2.0 of DNS-as-a-Service service") |
| 73 | return |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func endpointsFor(ces []CatalogEntry, t string) []Endpoint { |
| 78 | for _, ce := range ces { |
| 79 | if ce.Type == t { |
| 80 | return ce.Endpoints |
| 81 | } |
| 82 | } |
| 83 | panic("Precondition violated") |
| 84 | } |
| 85 | |
| 86 | func strNotInStrList(needle, haystack1, haystack2, haystack3 string) bool { |
| 87 | if (needle != haystack1) && (needle != haystack2) && (needle != haystack3) { |
| 88 | return true |
| 89 | } |
| 90 | return false |
Samuel A. Falvo II | 0262e97 | 2014-01-24 16:06:56 -0800 | [diff] [blame] | 91 | } |