forked from ctiom/kitchen
-
Notifications
You must be signed in to change notification settings - Fork 10
/
ContextForTest.go
107 lines (82 loc) · 2.26 KB
/
ContextForTest.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package kitchen
import (
"context"
)
// A ContextForTest is for mocking the Context struct for testing.
type ContextForTest[D ICookware] struct {
context.Context
SessionServed []IDishServe
DummyCookware D
DummyDish iDish[D]
DummySets []iSet[D]
DummyMenu iMenu[D]
webBundle IWebBundle
}
func (c *ContextForTest[D]) Session(serve ...IDishServe) []IDishServe {
c.SessionServed = append(c.SessionServed, serve...)
return c.SessionServed
}
func (c ContextForTest[D]) SetCtx(ctx context.Context) {
c.Context = ctx
}
func (c ContextForTest[D]) RawCookware() ICookware {
return c.DummyCookware
}
func (c ContextForTest[D]) Menu() iMenu[D] {
return c.DummyMenu
}
func (c ContextForTest[D]) Sets() []iSet[D] {
return c.DummySets
}
func (c ContextForTest[D]) Dish() iDish[D] {
return c.DummyDish
}
func (c ContextForTest[D]) Dependency() D {
return c.DummyCookware
}
func (c ContextForTest[D]) Cookware() D {
return c.DummyCookware
}
func (c ContextForTest[D]) traceableCookware() ITraceableCookware[D] {
return nil
}
func (c ContextForTest[D]) startTrace(id string, input any) iTraceSpan[D] {
return nil
}
func (c ContextForTest[D]) logSideEffect(instanceName string, toLog []any) (IContext[D], iTraceSpan[D]) {
return nil, nil
}
func (c ContextForTest[D]) WebBundle() IWebBundle {
return c.webBundle
}
func (c *ContextForTest[D]) SetWebBundle(body []byte, bundle IWebBundle) {
c.webBundle = bundle
}
func (c ContextForTest[D]) TraceSpan() iTraceSpan[D] {
return nil
}
func (c ContextForTest[D]) GetCtx() context.Context {
return c.Context
}
func (c *ContextForTest[D]) servedWeb() {
}
func (c *ContextForTest[D]) served() {}
func (c *ContextForTest[D]) setCookware(cookware D) {
c.DummyCookware = cookware
}
type PipelineContextForTest[D IPipelineCookware[M], M IPipelineModel] struct {
ContextForTest[D]
DummyTx IDbTx
}
func (b PipelineContextForTest[D, M]) Tx() IDbTx {
return b.DummyTx
}
func (b PipelineContextForTest[D, M]) Pipeline() iPipeline[D, M] {
return b.DummyMenu.(iPipeline[D, M])
}
func (b PipelineContextForTest[D, M]) Stage() iPipelineStage[D, M] {
return b.DummySets[0].(iPipelineStage[D, M])
}
func (c *PipelineContextForTest[D, M]) logSideEffect(instanceName string, toLog []any) (IContext[D], iTraceSpan[D]) {
return c, nil
}