1package config
2
3import (
4 "context"
5 "reflect"
6 "testing"
7)
8
9func TestBadFromContext(t *testing.T) {
10 ctx := context.TODO()
11 if c := FromContext(ctx); c != nil {
12 t.Errorf("FromContext(ctx) => %v, want %v", c, nil)
13 }
14}
15
16func TestGoodFromContext(t *testing.T) {
17 ctx := WithContext(context.TODO(), &Config{})
18 if c := FromContext(ctx); c == nil {
19 t.Errorf("FromContext(ctx) => %v, want %v", c, &Config{})
20 }
21}
22
23func TestGoodFromContextWithDefaultConfig(t *testing.T) {
24 cfg := DefaultConfig()
25 ctx := WithContext(context.TODO(), cfg)
26 if c := FromContext(ctx); c == nil || !reflect.DeepEqual(c, cfg) {
27 t.Errorf("FromContext(ctx) => %v, want %v", c, cfg)
28 }
29}