예제 #1
0
func TestForwardHandlerHandleTerminationEvent(t *testing.T) {
	t.Parallel()

	// create a handler
	kv := mocks.NewKVer()
	consul := consul.NewConsul(kv, "")
	handler := ForwardHandler{consul}

	err := consul.UpdateApp(testApp)
	assert.Nil(t, err)

	body, err := json.Marshal(events.AppTerminatedEvent{
		Type:  "app_terminated_event",
		AppID: testApp.ID,
	})
	assert.Nil(t, err)

	// test!
	recorder := httptest.NewRecorder()
	handler.HandleTerminationEvent(recorder, body)

	assert.Equal(t, 200, recorder.Code)
	assert.Equal(t, "OK\n", recorder.Body.String())

	result, _, err := kv.Get(testApp.Key())
	assert.Nil(t, err)
	assert.Nil(t, result)
}
예제 #2
0
func TestForwardHandlerHandleTerminationEvent(t *testing.T) {
	t.Parallel()

	// create a handler
	kv := mocks.NewKVer()
	consul := consul.NewConsul(kv, "")
	handler := ForwardHandler{consul}

	err := consul.UpdateApp(testApp)
	assert.Nil(t, err)

	body, err := json.Marshal(events.AppTerminatedEvent{
		Type:  "app_terminated_event",
		AppID: testApp.ID,
	})
	assert.Nil(t, err)

	// test!
	err = handler.HandleTerminationEvent(body)
	assert.Nil(t, err)

	result, _, err := kv.Get(testApp.Key())
	assert.Nil(t, err)
	assert.Nil(t, result)
}