Re-implement basic identity API for v0.2.0.
diff --git a/openstack/identity/extensions_test.go b/openstack/identity/extensions_test.go
index a5eede2..009d29d 100644
--- a/openstack/identity/extensions_test.go
+++ b/openstack/identity/extensions_test.go
@@ -5,48 +5,6 @@
"testing"
)
-// 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
-const queryResults = `{
- "extensions":[{
- "name": "Reset Password Extension",
- "namespace": "http://docs.rackspacecloud.com/identity/api/ext/rpe/v2.0",
- "alias": "RS-RPE",
- "updated": "2011-01-22T13:25:27-06:00",
- "description": "Adds the capability to reset a user's password. The user is emailed when the password has been reset.",
- "links":[{
- "rel": "describedby",
- "type": "application/pdf",
- "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-rpe-20111111.pdf"
- },
- {
- "rel": "describedby",
- "type": "application/vnd.sun.wadl+xml",
- "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-rpe.wadl"
- }
- ]
- },
- {
- "name": "User Metadata Extension",
- "namespace": "http://docs.rackspacecloud.com/identity/api/ext/meta/v2.0",
- "alias": "RS-META",
- "updated": "2011-01-12T11:22:33-06:00",
- "description": "Allows associating arbritrary metadata with a user.",
- "links":[{
- "rel": "describedby",
- "type": "application/pdf",
- "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-meta-20111201.pdf"
- },
- {
- "rel": "describedby",
- "type": "application/vnd.sun.wadl+xml",
- "href": "http://docs.rackspacecloud.com/identity/api/ext/identity-meta.wadl"
- }
- ]
- }
- ],
- "extensions_links":[]
-}`
-
func TestIsExtensionAvailable(t *testing.T) {
// Make a response as we'd expect from the IdentityService.GetExtensions() call.
getExtensionsResults := make(map[string]interface{})
@@ -56,7 +14,7 @@
return
}
- e := Extensions(getExtensionsResults)
+ e := ExtensionsResult(getExtensionsResults)
for _, alias := range []string{"RS-RPE", "RS-META"} {
if !e.IsExtensionAvailable(alias) {
t.Errorf("Expected extension %s present.", alias)
@@ -78,7 +36,7 @@
return
}
- e := Extensions(getExtensionsResults)
+ e := ExtensionsResult(getExtensionsResults)
ed, err := e.ExtensionDetailsByAlias("RS-META")
if err != nil {
t.Error(err)
@@ -106,3 +64,48 @@
}
}
}
+
+func TestMalformedResponses(t *testing.T) {
+ getExtensionsResults := make(map[string]interface{})
+ err := json.Unmarshal([]byte(bogusExtensionsResults), &getExtensionsResults)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ e := ExtensionsResult(getExtensionsResults)
+
+ _, err = e.ExtensionDetailsByAlias("RS-META")
+ if err == nil {
+ t.Error("Expected ErrNotImplemented at least")
+ return
+ }
+ if err != ErrNotImplemented {
+ t.Error("Expected ErrNotImplemented")
+ return
+ }
+
+ if e.IsExtensionAvailable("anything at all") {
+ t.Error("No extensions are available with a bogus result.")
+ return
+ }
+}
+
+func TestAliases(t *testing.T) {
+ getExtensionsResults := make(map[string]interface{})
+ err := json.Unmarshal([]byte(queryResults), &getExtensionsResults)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ e := ExtensionsResult(getExtensionsResults)
+ aliases, err := e.Aliases()
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if len(aliases) != len(e) {
+ t.Error("Expected one alias name per extension")
+ return
+ }
+}