containers unit tests
diff --git a/openstack/storage/v1/containers/containers_test.go b/openstack/storage/v1/containers/containers_test.go
new file mode 100644
index 0000000..3296bb1
--- /dev/null
+++ b/openstack/storage/v1/containers/containers_test.go
@@ -0,0 +1,78 @@
+package containers
+
+import (
+ "bytes"
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+ "reflect"
+ "testing"
+)
+
+
+func TestExtractContainerMetadata(t *testing.T) {
+ getResult := &http.Response{}
+
+ expected := map[string]string{}
+
+ actual := ExtractMetadata(getResult)
+
+ if !reflect.DeepEqual(expected, actual) {
+ t.Errorf("Expected: %+v\nActual:%+v", expected, actual)
+ }
+}
+
+func TestExtractContainerInfo(t *testing.T) {
+ responseBody := `
+ [
+ {
+ "count": 3,
+ "bytes": 2000,
+ "name": "artemis"
+ },
+ {
+ "count": 1,
+ "bytes": 450,
+ "name": "diana"
+ }
+ ]
+ `
+
+ listResult := &http.Response{
+ Body: ioutil.NopCloser(bytes.NewBufferString(responseBody)),
+ }
+
+ var expected []Container
+ err := json.Unmarshal([]byte(responseBody), &expected)
+ if err != nil {
+ t.Errorf("Error unmarshaling JSON: %s", err)
+ }
+
+ actual, err := ExtractInfo(listResult)
+ if err != nil {
+ t.Errorf("Error extracting containers info: %s", err)
+ }
+
+ if !reflect.DeepEqual(expected, actual) {
+ t.Errorf("\nExpected: %+v\nActual: %+v", expected, actual)
+ }
+}
+
+func TestExtractConatinerNames(t *testing.T) {
+ responseBody := "artemis\ndiana\n"
+
+ listResult := &http.Response{
+ Body: ioutil.NopCloser(bytes.NewBufferString(responseBody)),
+ }
+
+ expected := []string{"artemis", "diana"}
+
+ actual, err := ExtractNames(listResult)
+ if err != nil {
+ t.Errorf("Error extracting container names: %s", err)
+ }
+
+ if !reflect.DeepEqual(expected, actual) {
+ t.Errorf("Expected: %+v\nActual:%+v", expected, actual)
+ }
+}
diff --git a/openstack/storage/v1/containers/requests_test.go b/openstack/storage/v1/containers/requests_test.go
new file mode 100644
index 0000000..871cb21
--- /dev/null
+++ b/openstack/storage/v1/containers/requests_test.go
@@ -0,0 +1,136 @@
+package containers
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/testhelper"
+)
+
+const (
+ tokenId = "abcabcabcabc"
+)
+
+var metadata = map[string]string{"gophercloud-test": "containers"}
+
+func serviceClient() *gophercloud.ServiceClient {
+ return &gophercloud.ServiceClient{
+ Provider: &gophercloud.ProviderClient{TokenID: tokenId},
+ Endpoint: testhelper.Endpoint(),
+ }
+}
+
+func TestListContainerInfo(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+
+ testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testhelper.TestMethod(t, r, "GET")
+ testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "Accept", "application/json")
+ })
+
+ client := serviceClient()
+ _, err := List(client, ListOpts{Full: true})
+ if err != nil {
+ t.Fatalf("Unexpected error listing containers info: %v", err)
+ }
+}
+
+func TestListContainerNames(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+
+ testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testhelper.TestMethod(t, r, "GET")
+ testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "Accept", "text/plain")
+ })
+
+ client := serviceClient()
+ _, err := List(client, ListOpts{})
+ if err != nil {
+ t.Fatalf("Unexpected error listing containers info: %v", err)
+ }
+}
+
+func TestCreateContainer(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+
+ testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
+ testhelper.TestMethod(t, r, "PUT")
+ testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "Accept", "application/json")
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ client := serviceClient()
+ _, err := Create(client, CreateOpts{
+ Name: "testContainer",
+ })
+ if err != nil {
+ t.Fatalf("Unexpected error creating container: %v", err)
+ }
+}
+
+func TestDeleteContainer(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+
+ testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
+ testhelper.TestMethod(t, r, "DELETE")
+ testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "Accept", "application/json")
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ client := serviceClient()
+ err := Delete(client, DeleteOpts{
+ Name: "testContainer",
+ })
+ if err != nil {
+ t.Fatalf("Unexpected error deleting container: %v", err)
+ }
+}
+
+func TestUpateContainer(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+
+ testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
+ testhelper.TestMethod(t, r, "POST")
+ testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "Accept", "application/json")
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ client := serviceClient()
+ err := Update(client, UpdateOpts{
+ Name: "testContainer",
+ })
+ if err != nil {
+ t.Fatalf("Unexpected error updating container metadata: %v", err)
+ }
+}
+
+func TestGetContainer(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+
+ testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
+ testhelper.TestMethod(t, r, "HEAD")
+ testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "Accept", "application/json")
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ client := serviceClient()
+ _, err := Get(client, GetOpts{
+ Name: "testContainer",
+ })
+ if err != nil {
+ t.Fatalf("Unexpected error getting container metadata: %v", err)
+ }
+}
diff --git a/openstack/storage/v1/containers/urls_test.go b/openstack/storage/v1/containers/urls_test.go
new file mode 100644
index 0000000..da37bf6
--- /dev/null
+++ b/openstack/storage/v1/containers/urls_test.go
@@ -0,0 +1,29 @@
+package containers
+
+import (
+ "testing"
+ "github.com/rackspace/gophercloud"
+)
+
+func TestAccountURL(t *testing.T) {
+ client := gophercloud.ServiceClient{
+ Endpoint: "http://localhost:5000/v1/",
+ }
+ expected := "http://localhost:5000/v1/"
+ actual := accountURL(&client)
+ if actual != expected {
+ t.Errorf("Unexpected service URL generated: [%s]", actual)
+ }
+
+}
+
+func TestContainerURL(t *testing.T) {
+ client := gophercloud.ServiceClient{
+ Endpoint: "http://localhost:5000/v1/",
+ }
+ expected := "http://localhost:5000/v1/testContainer"
+ actual := containerURL(&client, "testContainer")
+ if actual != expected {
+ t.Errorf("Unexpected service URL generated: [%s]", actual)
+ }
+}