Exemple #1
0
// instances:methods
func TestInstancesMethodInvalid(t *testing.T) {
	const fake = "fakeid"
	var methods = []string{"CONNECT", "DELETE", "HEAD", "OPTIONS", "PATCH", "PUT", "TRACE"}
	var urls = []string{
		serverURL + amalgam8.InstanceCreateURL(),
		serverURL + amalgam8.InstanceURL(fake),
	}

	c := defaultServerConfig()
	handler, err := setupServer(c)
	assert.Nil(t, err)

	assert.Nil(t, err)
	for _, url := range urls {
		for _, method := range methods {
			if method == "DELETE" && url == serverURL+amalgam8.InstanceURL(fake) {
				continue // this is a valid combination
			}
			recorder := httptest.NewRecorder()
			req, err := http.NewRequest(method, url, nil)
			assert.Nil(t, err)
			handler.ServeHTTP(recorder, req)
			assert.Equal(t, http.StatusMethodNotAllowed, recorder.Code, method+":"+url)
		}
	}
}
Exemple #2
0
// instance:delete
func TestInstanceDelete(t *testing.T) {
	cases := []struct {
		iid      string // input service identifier
		expected int    // expected result
	}{
		{"http-1", http.StatusOK},
		{"http-2", http.StatusOK},
		{"http-2", http.StatusGone}, // duplicate delete should fail
		{"http-3", http.StatusGone}, // unknown instance id should fail
	}

	c := defaultServerConfig()
	c.Registry.(*mockCatalog).prepopulateInstances(instances)
	handler, err := setupServer(c)
	assert.Nil(t, err)

	for _, tc := range cases {
		recorder := httptest.NewRecorder()

		req, err := http.NewRequest("DELETE", serverURL+amalgam8.InstanceURL(tc.iid), nil)
		assert.Nil(t, err)
		req.Header.Set("Content-Type", "application/json")
		handler.ServeHTTP(recorder, req)
		assert.Equal(t, tc.expected, recorder.Code, string(tc.iid))
	}

	recorder := httptest.NewRecorder()

	req, err := http.NewRequest("GET", serverURL+amalgam8.ServiceInstancesURL("http"), nil)
	assert.Nil(t, err)
	req.Header.Set("Content-Type", "application/json")
	handler.ServeHTTP(recorder, req)
	assert.Equal(t, http.StatusNotFound, recorder.Code)
}
Exemple #3
0
func (client *client) Deregister(id string) error {
	_, err := client.doRequest("DELETE", amalgam8.InstanceURL(id), nil, http.StatusOK)
	return err
}