MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestNamespace

Function TestNamespace

pkg/webmiddleware/namespace_test.go:30–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestNamespace(t *testing.T) {
31 a := assertions.New(t)
32
33 mem := memory.New()
34 logger := log.NewLogger(mem)
35
36 ctx := log.NewContext(test.Context(), logger)
37
38 m := Namespace("test")
39 req := httptest.NewRequest(http.MethodGet, "/", nil).WithContext(ctx)
40 rec := httptest.NewRecorder()
41 m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
42 log.FromContext(r.Context()).Info("foobar")
43 entry := mem.Entries[0]
44 a.So(entry.Message(), should.Equal, "foobar")
45 fields := entry.Fields().Fields()
46 a.So(fields, should.HaveLength, 1)
47 a.So(fields["namespace"], should.Equal, "test")
48 })).ServeHTTP(rec, req)
49}

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
NewLoggerFunction · 0.92
NewContextFunction · 0.92
ContextFunction · 0.92
FromContextFunction · 0.92
NamespaceFunction · 0.85
NewMethod · 0.65
InfoMethod · 0.65
ContextMethod · 0.65
MessageMethod · 0.65
FieldsMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected