Esempio n. 1
0
func TestUpdate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "PUT")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		th.TestHeader(t, r, "Content-Type", "application/json")
		th.TestHeader(t, r, "Accept", "application/json")
		th.TestJSONRequest(t, r, `
{
		"network": {
				"router:external": true,
				"name": "new_name"
		}
}
			`)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
	"network": {
			"admin_state_up": true,
			"id": "8d05a1b1-297a-46ca-8974-17debf51ca3c",
			"name": "new_name",
			"router:external": true,
			"shared": false,
			"status": "ACTIVE",
			"subnets": [
					"2f1fb918-9b0e-4bf9-9a50-6cebbb4db2c5"
			],
			"tenant_id": "5eb8995cf717462c9df8d1edfa498010"
	}
}
		`)
	})

	options := external.UpdateOpts{networks.UpdateOpts{Name: "new_name"}, gophercloud.Enabled}
	res := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options)
	n, err := external.ExtractUpdate(res)

	th.AssertNoErr(t, err)
	th.AssertEquals(t, true, n.External)
}
Esempio n. 2
0
func TestExtractFnsReturnsErrWhenResultContainsErr(t *testing.T) {
	gr := networks.GetResult{}
	gr.Err = errors.New("")

	if _, err := external.ExtractGet(gr); err == nil {
		t.Fatalf("Expected error, got one")
	}

	ur := networks.UpdateResult{}
	ur.Err = errors.New("")

	if _, err := external.ExtractUpdate(ur); err == nil {
		t.Fatalf("Expected error, got one")
	}

	cr := networks.CreateResult{}
	cr.Err = errors.New("")

	if _, err := external.ExtractCreate(cr); err == nil {
		t.Fatalf("Expected error, got one")
	}
}