-
Notifications
You must be signed in to change notification settings - Fork 145
/
param_context.go
53 lines (40 loc) · 1.04 KB
/
param_context.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
package testutils
import (
"context"
"github.com/hatchet-dev/hatchet/api/v1/server/serverutils"
)
type TestContext struct {
ctx context.Context
params map[string]string
}
func GetTestContext(params map[string]string) serverutils.ParamContext {
return &TestContext{context.Background(), params}
}
// Get retrieves data from the context.
func (t *TestContext) Get(key string) any {
return t.ctx.Value(key)
}
// Set saves data in the context.
func (t *TestContext) Set(key string, val any) {
t.ctx = context.WithValue(t.ctx, key, val)
}
// Param returns path parameter by name.
func (t *TestContext) Param(name string) string {
return t.params[name]
}
// ParamNames returns path parameter names.
func (t *TestContext) ParamNames() []string {
names := []string{}
for name := range t.params {
names = append(names, name)
}
return names
}
// ParamValues returns path parameter values.
func (t *TestContext) ParamValues() []string {
values := []string{}
for _, val := range t.params {
values = append(values, val)
}
return values
}