MCPcopy
hub / github.com/supabase/auth / TestAtomicHandler

Function TestAtomicHandler

internal/reloader/handler_test.go:11–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestAtomicHandler(t *testing.T) {
12 // for ptr identity
13 type testHandler struct{ http.Handler }
14
15 var calls atomic.Int64
16 hrFn := func() http.Handler {
17 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18 calls.Add(1)
19 })
20 }
21
22 hrFunc1 := &testHandler{hrFn()}
23 hrFunc2 := &testHandler{hrFn()}
24 assert.NotEqual(t, hrFunc1, hrFunc2)
25
26 // a new AtomicHandler should be non-nil
27 hr := NewAtomicHandler(hrFunc1)
28 assert.NotNil(t, hr)
29 assert.Equal(t, "reloader.AtomicHandler", hr.String())
30
31 // should implement http.Handler
32 {
33 v := (http.Handler)(hr)
34 before := calls.Load()
35 v.ServeHTTP(nil, nil)
36 after := calls.Load()
37 if exp, got := before+1, after; exp != got {
38 t.Fatalf("exp %v to be %v after handler was called", got, exp)
39 }
40 }
41
42 // should be non-nil after store
43 for i := 0; i < 3; i++ {
44 hr.Store(hrFunc1)
45 assert.NotNil(t, hr.load())
46 assert.Equal(t, hr.load(), hrFunc1)
47 assert.Equal(t, hr.load() == hrFunc1, true)
48
49 // should update to hrFunc2
50 hr.Store(hrFunc2)
51 assert.NotNil(t, hr.load())
52 assert.Equal(t, hr.load(), hrFunc2)
53 assert.Equal(t, hr.load() == hrFunc2, true)
54 }
55}

Callers

nothing calls this directly

Calls 7

StringMethod · 0.95
StoreMethod · 0.95
loadMethod · 0.95
NewAtomicHandlerFunction · 0.85
EqualMethod · 0.80
AddMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…