blob: a5eede2e026bccb779ec25553421229572babb0a [file] [log] [blame]
Samuel A. Falvo II8a549ef2014-01-24 15:20:54 -08001package identity
2
3import (
4 "encoding/json"
5 "testing"
6)
7
8// Taken from: http://docs.openstack.org/api/openstack-identity-service/2.0/content/GET_listExtensions_v2.0_extensions_.html#GET_listExtensions_v2.0_extensions_-Request
9const queryResults = `{
10 "extensions":[{
11 "name": "Reset Password Extension",
12 "namespace": "http://docs.rackspacecloud.com/identity/api/ext/rpe/v2.0",
13 "alias": "RS-RPE",
14 "updated": "2011-01-22T13:25:27-06:00",
15 "description": "Adds the capability to reset a user's password. The user is emailed when the password has been reset.",
16 "links":[{
17 "rel": "describedby",
18 "type": "application/pdf",
19 "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-rpe-20111111.pdf"
20 },
21 {
22 "rel": "describedby",
23 "type": "application/vnd.sun.wadl+xml",
24 "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-rpe.wadl"
25 }
26 ]
27 },
28 {
29 "name": "User Metadata Extension",
30 "namespace": "http://docs.rackspacecloud.com/identity/api/ext/meta/v2.0",
31 "alias": "RS-META",
32 "updated": "2011-01-12T11:22:33-06:00",
33 "description": "Allows associating arbritrary metadata with a user.",
34 "links":[{
35 "rel": "describedby",
36 "type": "application/pdf",
37 "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-meta-20111201.pdf"
38 },
39 {
40 "rel": "describedby",
41 "type": "application/vnd.sun.wadl+xml",
42 "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-meta.wadl"
43 }
44 ]
45 }
46 ],
47 "extensions_links":[]
48}`
49
50func TestIsExtensionAvailable(t *testing.T) {
51 // Make a response as we'd expect from the IdentityService.GetExtensions() call.
52 getExtensionsResults := make(map[string]interface{})
53 err := json.Unmarshal([]byte(queryResults), &getExtensionsResults)
54 if err != nil {
55 t.Error(err)
56 return
57 }
58
59 e := Extensions(getExtensionsResults)
60 for _, alias := range []string{"RS-RPE", "RS-META"} {
61 if !e.IsExtensionAvailable(alias) {
62 t.Errorf("Expected extension %s present.", alias)
63 return
64 }
65 }
66 if e.IsExtensionAvailable("blort") {
67 t.Errorf("Input JSON doesn't list blort as an extension")
68 return
69 }
70}
71
72func TestGetExtensionDetails(t *testing.T) {
73 // Make a response as we'd expect from the IdentityService.GetExtensions() call.
74 getExtensionsResults := make(map[string]interface{})
75 err := json.Unmarshal([]byte(queryResults), &getExtensionsResults)
76 if err != nil {
77 t.Error(err)
78 return
79 }
80
81 e := Extensions(getExtensionsResults)
82 ed, err := e.ExtensionDetailsByAlias("RS-META")
83 if err != nil {
84 t.Error(err)
85 return
86 }
87
88 actuals := map[string]string{
89 "name": ed.Name,
90 "namespace": ed.Namespace,
91 "updated": ed.Updated,
92 "description": ed.Description,
93 }
94
95 expecteds := map[string]string{
96 "name": "User Metadata Extension",
97 "namespace": "http://docs.rackspacecloud.com/identity/api/ext/meta/v2.0",
98 "updated": "2011-01-12T11:22:33-06:00",
99 "description": "Allows associating arbritrary metadata with a user.",
100 }
101
102 for k, v := range expecteds {
103 if actuals[k] != v {
104 t.Errorf("Expected %s \"%s\", got \"%s\" instead", k, v, actuals[k])
105 return
106 }
107 }
108}