This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
array_tests_base.go
103 lines (82 loc) · 2.67 KB
/
array_tests_base.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
package array
import (
"testing"
"github.com/flyteorg/flyteplugins/tests"
idlCore "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/plugins"
"github.com/flyteorg/flytestdlib/utils"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
"context"
"github.com/stretchr/testify/assert"
"github.com/flyteorg/flyteidl/clients/go/coreutils"
)
type AdvanceIteration func(ctx context.Context, tCtx core.TaskExecutionContext) error
func RunArrayTestsEndToEnd(t *testing.T, executor core.Plugin, iter AdvanceIteration) {
inputs := coreutils.MustMakeLiteral(map[string]interface{}{
"x": 5,
}).GetMap()
t.Run("Regular container task", func(t *testing.T) {
template := tests.BuildTaskTemplate()
tests.RunPluginEndToEndTest(t, executor, template, inputs, nil, nil, iter)
})
t.Run("Array of size 1. No cache", func(t *testing.T) {
template := tests.BuildTaskTemplate()
template.Interface = &idlCore.TypedInterface{
Inputs: nil,
Outputs: &idlCore.VariableMap{
Variables: map[string]*idlCore.Variable{
"x": {
Type: &idlCore.LiteralType{
Type: &idlCore.LiteralType_CollectionType{
CollectionType: &idlCore.LiteralType{Type: &idlCore.LiteralType_Simple{Simple: idlCore.SimpleType_INTEGER}},
},
},
},
},
},
}
var err error
template.Custom, err = utils.MarshalPbToStruct(&plugins.ArrayJob{
Parallelism: 10,
Size: 1,
SuccessCriteria: &plugins.ArrayJob_MinSuccesses{
MinSuccesses: 1,
},
})
assert.NoError(t, err)
expectedOutputs := coreutils.MustMakeLiteral(map[string]interface{}{
"x": []interface{}{5},
}).GetMap()
tests.RunPluginEndToEndTest(t, executor, template, inputs, expectedOutputs, nil, iter)
})
t.Run("Array of size 2. No cache", func(t *testing.T) {
template := tests.BuildTaskTemplate()
template.Interface = &idlCore.TypedInterface{
Inputs: nil,
Outputs: &idlCore.VariableMap{
Variables: map[string]*idlCore.Variable{
"x": {
Type: &idlCore.LiteralType{
Type: &idlCore.LiteralType_CollectionType{
CollectionType: &idlCore.LiteralType{Type: &idlCore.LiteralType_Simple{Simple: idlCore.SimpleType_INTEGER}},
},
},
},
},
},
}
var err error
template.Custom, err = utils.MarshalPbToStruct(&plugins.ArrayJob{
Parallelism: 10,
Size: 2,
SuccessCriteria: &plugins.ArrayJob_MinSuccesses{
MinSuccesses: 1,
},
})
assert.NoError(t, err)
expectedOutputs := coreutils.MustMakeLiteral(map[string]interface{}{
"x": []interface{}{5, 5},
}).GetMap()
tests.RunPluginEndToEndTest(t, executor, template, inputs, expectedOutputs, nil, iter)
})
}