(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestActivatorHandler_ServeHTTP(t *testing.T) { |
| 31 | t.Parallel() |
| 32 | |
| 33 | log := newLogger(t) |
| 34 | |
| 35 | apiName := "test" |
| 36 | act := &activator{ |
| 37 | autoscalerClient: autoscalerClientMock{}, |
| 38 | apiActivators: map[string]*apiActivator{ |
| 39 | apiName: newAPIActivator(1, 1), |
| 40 | }, |
| 41 | readinessTrackers: map[string]*readinessTracker{ |
| 42 | apiName: {ready: true}, |
| 43 | }, |
| 44 | logger: log, |
| 45 | } |
| 46 | |
| 47 | ah := NewHandler(act, log) |
| 48 | |
| 49 | var callCount int |
| 50 | server := httptest.NewServer( |
| 51 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 52 | callCount++ |
| 53 | w.WriteHeader(http.StatusOK) |
| 54 | }), |
| 55 | ) |
| 56 | |
| 57 | w := httptest.NewRecorder() |
| 58 | r := httptest.NewRequest("POST", "http://fake.cortex.dev/api", nil) |
| 59 | r.Header.Set(consts.CortexAPINameHeader, apiName) |
| 60 | r.Header.Set(consts.CortexTargetServiceHeader, server.URL) |
| 61 | |
| 62 | ah.ServeHTTP(w, r) |
| 63 | |
| 64 | require.Equal(t, http.StatusOK, w.Code) |
| 65 | require.Equal(t, 1, callCount) |
| 66 | } |
nothing calls this directly
no test coverage detected