// instance:heartbeat func TestInstanceHeartbeat(t *testing.T) { cases := []struct { iid string // input service identifier expected int // expected result }{ {"http-1", http.StatusOK}, {"http-2", http.StatusOK}, {"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() // Consider getting the heartbeat URL of instances programmatically? req, err := http.NewRequest("PUT", serverURL+amalgam8.InstanceHeartbeatURL(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)) } }
func renew(t *testing.T, port uint16, id string) { url := fmt.Sprintf("http://localhost:%d%s", port, amalgam8.InstanceHeartbeatURL(id)) req, err1 := http.NewRequest("PUT", url, nil) assert.NoError(t, err1) assert.NotNil(t, req) req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Forwarded-Proto", "https") res, err2 := http.DefaultClient.Do(req) assert.NoError(t, err2) assert.NotNil(t, res) assert.EqualValues(t, 200, res.StatusCode) res.Body.Close() }
func (client *client) Renew(id string) error { _, err := client.doRequest("PUT", amalgam8.InstanceHeartbeatURL(id), nil, http.StatusOK) return err }