(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | |
| 64 | func TestCtxExtract(t *testing.T) { |
| 65 | t.Parallel() |
nothing calls this directly
no test coverage detected