MCPcopy Index your code
hub / github.com/cortexlabs/cortex / TestActivatorHandler_ServeHTTP

Function TestActivatorHandler_ServeHTTP

pkg/activator/handler_test.go:30–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func 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}

Callers

nothing calls this directly

Calls 6

ServeHTTPMethod · 0.95
newAPIActivatorFunction · 0.85
SetMethod · 0.80
EqualMethod · 0.80
newLoggerFunction · 0.70
NewHandlerFunction · 0.70

Tested by

no test coverage detected