fix for hanging unit tests
diff --git a/openstack/storage/v1/containers/requests.go b/openstack/storage/v1/containers/requests.go
index 3a6a265..35bc1af 100644
--- a/openstack/storage/v1/containers/requests.go
+++ b/openstack/storage/v1/containers/requests.go
@@ -80,7 +80,7 @@
OkCodes: []int{201, 204},
})
if err == nil {
- container = Container{"name": containerName}
+ container = Container{Name: containerName}
}
return container, err
}
diff --git a/openstack/storage/v1/containers/requests_test.go b/openstack/storage/v1/containers/requests_test.go
index 3b59e00..93747be 100644
--- a/openstack/storage/v1/containers/requests_test.go
+++ b/openstack/storage/v1/containers/requests_test.go
@@ -33,14 +33,29 @@
testhelper.TestHeader(t, r, "Accept", "application/json")
w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, `[{'count': 0,'bytes': 0,'name': 'janeausten'},{'count': 1,'bytes': 14,'name': 'marktwain'}]`)
+ r.ParseForm()
+ marker := r.Form.Get("marker")
+ switch marker {
+ case "":
+ fmt.Fprintf(w, `[
+ {
+ "count": 0,
+ "bytes": 0,
+ "name": "janeausten"
+ },
+ {
+ "count": 1,
+ "bytes": 14,
+ "name": "marktwain"
+ }
+ ]`)
+ default:
+ t.Fatalf("Unexpected marker: [%s]", marker)
+ }
})
client := serviceClient()
- count := 0
List(client, ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
- count++
actual, err := ExtractInfo(page)
if err != nil {
t.Errorf("Failed to extract container info: %v", err)
@@ -49,14 +64,14 @@
expected := []Container{
Container{
- "count": 0,
- "bytes": 0,
- "name": "janeausten",
+ Count: 0,
+ Bytes: 0,
+ Name: "janeausten",
},
Container{
- "count": 1,
- "bytes": 14,
- "name": "marktwain",
+ Count: 1,
+ Bytes: 14,
+ Name: "marktwain",
},
}
@@ -64,10 +79,6 @@
return true, nil
})
-
- if count != 1 {
- t.Errorf("Expected 1 page, got %d", count)
- }
}
func TestListContainerNames(t *testing.T) {
@@ -85,9 +96,7 @@
})
client := serviceClient()
- count := 0
List(client, ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
- count++
actual, err := ExtractNames(page)
if err != nil {
t.Errorf("Failed to extract container names: %v", err)
@@ -100,10 +109,6 @@
return true, nil
})
-
- if count != 0 {
- t.Fatalf("Expected 0 pages, got %d", count)
- }
}
func TestCreateContainer(t *testing.T) {
diff --git a/openstack/storage/v1/containers/results.go b/openstack/storage/v1/containers/results.go
index 6a93b4d..283e44a 100644
--- a/openstack/storage/v1/containers/results.go
+++ b/openstack/storage/v1/containers/results.go
@@ -9,7 +9,11 @@
"strings"
)
-type Container map[string]interface{}
+type Container struct {
+ Bytes int
+ Count int
+ Name string
+}
type commonResult struct {
gophercloud.CommonResult
@@ -79,7 +83,11 @@
untyped := page.(ContainerPage).Body.([]interface{})
results := make([]Container, len(untyped))
for index, each := range untyped {
- results[index] = Container(each.(map[string]interface{}))
+ container := each.(map[string]interface{})
+ err := mapstructure.Decode(container, results[index])
+ if err != nil {
+ return results, err
+ }
}
return results, nil
}
@@ -98,7 +106,7 @@
names := make([]string, 0, len(parsed))
for _, container := range parsed {
- names = append(names, container["name"].(string))
+ names = append(names, container.Name)
}
return names, nil
case strings.HasPrefix(ct, "text/plain"):