// instance:delete func TestEurekaInstanceDelete(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(eurekaInstances) handler, err := setupServer(c) assert.Nil(t, err) for _, tc := range cases { recorder := httptest.NewRecorder() req, err := http.NewRequest("DELETE", serverURL+eureka.InstanceURL("", "http", 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+eureka.ApplicationURL("", "http"), nil) assert.Nil(t, err) req.Header.Set("Content-Type", "application/json") handler.ServeHTTP(recorder, req) assert.Equal(t, http.StatusOK, recorder.Code) }
// instance:status func TestEurekaInstanceStatus(t *testing.T) { cases := []struct { iid string // input service identifier status string // input instance status expected int // expected result }{ {"http-1", "UP", http.StatusOK}, {"http-2", "DOWN", http.StatusOK}, {"http-3", "UNKNOWN", http.StatusNotFound}, // unknown instance id should fail } c := defaultServerConfig() c.Registry.(*mockCatalog).prepopulateInstances(eurekaInstances) handler, err := setupServer(c) assert.Nil(t, err) for _, tc := range cases { recorder := httptest.NewRecorder() req, err := http.NewRequest("PUT", serverURL+eureka.InstanceStatusURL("", "http", tc.iid)+"?value="+tc.status, 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)) if tc.expected == http.StatusOK { // Verify that the status was changed var inst eureka.InstanceWrapper req, err = http.NewRequest("GET", serverURL+eureka.InstanceURL("", "http", 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(http.StatusOK)) err = json.Unmarshal(recorder.Body.Bytes(), &inst) assert.Nil(t, err) assert.EqualValues(t, tc.status, inst.Inst.Status) } } }