-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_test.go
More file actions
63 lines (49 loc) · 1.18 KB
/
context_test.go
File metadata and controls
63 lines (49 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package forgeui
import (
"context"
"testing"
)
func TestWithTheme(t *testing.T) {
ctx := context.Background()
theme := "dark"
ctx = WithTheme(ctx, theme)
retrieved, ok := ThemeFromContext(ctx)
if !ok {
t.Error("ThemeFromContext() returned false, expected true")
}
if retrieved != theme {
t.Errorf("ThemeFromContext() = %v, want %v", retrieved, theme)
}
}
func TestThemeFromContext_NotSet(t *testing.T) {
ctx := context.Background()
_, ok := ThemeFromContext(ctx)
if ok {
t.Error("ThemeFromContext() returned true for empty context, expected false")
}
}
func TestWithConfig(t *testing.T) {
ctx := context.Background()
cfg := &Config{
Debug: true,
Theme: "custom",
}
ctx = WithConfig(ctx, cfg)
retrieved, ok := ConfigFromContext(ctx)
if !ok {
t.Error("ConfigFromContext() returned false, expected true")
}
if retrieved != cfg {
t.Error("ConfigFromContext() returned different config")
}
if !retrieved.Debug {
t.Error("Config Debug should be true")
}
}
func TestConfigFromContext_NotSet(t *testing.T) {
ctx := context.Background()
_, ok := ConfigFromContext(ctx)
if ok {
t.Error("ConfigFromContext() returned true for empty context, expected false")
}
}