-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyscript_mocks_test.go
More file actions
100 lines (86 loc) · 1.99 KB
/
Copy pathpolyscript_mocks_test.go
File metadata and controls
100 lines (86 loc) · 1.99 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
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
package polyscript_test
import (
"context"
"fmt"
"time"
"github.com/robbyt/go-polyscript/platform"
"github.com/robbyt/go-polyscript/platform/data"
"github.com/robbyt/go-polyscript/platform/script"
"github.com/stretchr/testify/mock"
)
type mockEvaluator struct {
mock.Mock
}
func (m *mockEvaluator) Eval(ctx context.Context) (platform.EvaluatorResponse, error) {
args := m.Called(ctx)
return args.Get(0).(platform.EvaluatorResponse), args.Error(1)
}
func (m *mockEvaluator) Reload(path string) error {
args := m.Called(path)
return args.Error(0)
}
func (m *mockEvaluator) Load(newVersion script.ExecutableUnit) error {
args := m.Called(newVersion)
return args.Error(0)
}
func (m *mockEvaluator) AddDataToContext(
ctx context.Context,
d map[string]any,
) (context.Context, error) {
args := m.Called(ctx, d)
return args.Get(0).(context.Context), args.Error(1)
}
type mockEvaluatorResponse struct {
mock.Mock
}
func (m *mockEvaluatorResponse) Type() data.Types {
args := m.Called()
val := args.Get(0)
if t, ok := val.(data.Types); ok {
return t
}
switch val.(type) {
case bool:
return data.BOOL
case int:
return data.INT
case map[string]any, map[any]any:
return data.MAP
case string:
return data.STRING
default:
panic("unknown type")
}
}
func (m *mockEvaluatorResponse) Inspect() string {
args := m.Called()
return args.String(0)
}
func (m *mockEvaluatorResponse) Interface() any {
args := m.Called()
return args.Get(0)
}
func (m *mockEvaluatorResponse) ScriptExeID() string {
args := m.Called()
return args.String(0)
}
func (m *mockEvaluatorResponse) ExecTime() time.Duration {
args := m.Called()
return args.Get(0).(time.Duration)
}
func (m *mockEvaluatorResponse) AsMap() (map[string]any, error) {
args := m.Called()
err := args.Error(1)
got := args.Get(0)
if got == nil {
return nil, err
}
m0, ok := got.(map[string]any)
if !ok {
if err != nil {
return nil, err
}
return nil, fmt.Errorf("AsMap: expected map[string]any, got %T", got)
}
return m0, err
}