MCPcopy Create free account
hub / github.com/belak/gitdir / TestContextKey

Function TestContextKey

context_test.go:14–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestContextKey(t *testing.T) {
15 t.Parallel()
16
17 var tests = []struct { //nolint:gofumpt
18 Input contextKey
19 Base string
20 Expected string
21 }{
22 {
23 contextKey("hello world"),
24 "hello world",
25 "Context key: hello world",
26 },
27 {
28 contextKeyConfig,
29 "gitdir-config",
30 "Context key: gitdir-config",
31 },
32 {
33 contextKeyUser,
34 "gitdir-user",
35 "Context key: gitdir-user",
36 },
37 {
38 contextKeyLogger,
39 "gitdir-logger",
40 "Context key: gitdir-logger",
41 },
42 {
43 contextKeyPublicKey,
44 "gitdir-public-key",
45 "Context key: gitdir-public-key",
46 },
47 }
48
49 baseCtx := context.Background()
50
51 for _, test := range tests {
52 assert.Equal(t, test.Expected, test.Input.String())
53
54 ctx := context.WithValue(baseCtx, test.Input, "hello world")
55
56 // Make sure you can't pull values out with the raw string
57 assert.Nil(t, ctx.Value(test.Base))
58
59 // Assert values come out properly
60 assert.Equal(t, "hello world", ctx.Value(test.Input))
61 }
62}
63
64func TestCtxExtract(t *testing.T) {
65 t.Parallel()

Callers

nothing calls this directly

Calls 2

contextKeyTypeAlias · 0.85
StringMethod · 0.45

Tested by

no test coverage detected