Identity v3 Projects Create (#165)
* Identity v3 Projects Create
* Removing unused createErr function
diff --git a/openstack/identity/v3/projects/testing/fixtures.go b/openstack/identity/v3/projects/testing/fixtures.go
index cb10313..0c839b8 100644
--- a/openstack/identity/v3/projects/testing/fixtures.go
+++ b/openstack/identity/v3/projects/testing/fixtures.go
@@ -55,6 +55,16 @@
}
`
+// CreateRequest provides the input to a Create request.
+const CreateRequest = `
+{
+ "project": {
+ "description": "The team that is red",
+ "name": "Red Team"
+ }
+}
+`
+
// RedTeam is a Project fixture.
var RedTeam = projects.Project{
IsDomain: false,
@@ -107,3 +117,16 @@
fmt.Fprintf(w, GetOutput)
})
}
+
+// HandleCreateProjectSuccessfully creates an HTTP handler at `/projects` on the
+// test handler mux that tests project creation.
+func HandleCreateProjectSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, CreateRequest)
+
+ w.WriteHeader(http.StatusCreated)
+ fmt.Fprintf(w, GetOutput)
+ })
+}
diff --git a/openstack/identity/v3/projects/testing/requests_test.go b/openstack/identity/v3/projects/testing/requests_test.go
index eeb2049..daed4eb 100644
--- a/openstack/identity/v3/projects/testing/requests_test.go
+++ b/openstack/identity/v3/projects/testing/requests_test.go
@@ -38,3 +38,18 @@
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, RedTeam, *actual)
}
+
+func TestCreateProject(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleCreateProjectSuccessfully(t)
+
+ createOpts := projects.CreateOpts{
+ Name: "Red Team",
+ Description: "The team that is red",
+ }
+
+ actual, err := projects.Create(client.ServiceClient(), createOpts).Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, RedTeam, *actual)
+}