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 59
/
literals.go
81 lines (74 loc) · 2.24 KB
/
literals.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
package assert
import (
"reflect"
"testing"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/stretchr/testify/assert"
)
func EqualPrimitive(t *testing.T, p1 *core.Primitive, p2 *core.Primitive) {
if !assert.Equal(t, p1 == nil, p2 == nil) {
assert.FailNow(t, "One of the values is nil")
}
if p1 == nil {
return
}
assert.Equal(t, reflect.TypeOf(p1.Value), reflect.TypeOf(p2.Value))
switch p1.Value.(type) {
case *core.Primitive_Integer:
assert.Equal(t, p1.GetInteger(), p2.GetInteger())
case *core.Primitive_StringValue:
assert.Equal(t, p1.GetStringValue(), p2.GetStringValue())
default:
assert.FailNow(t, "Not yet implemented for types %v", reflect.TypeOf(p1.Value))
}
}
func EqualScalar(t *testing.T, p1 *core.Scalar, p2 *core.Scalar) {
if !assert.Equal(t, p1 == nil, p2 == nil) {
assert.FailNow(t, "One of the values is nil")
}
if p1 == nil {
return
}
assert.Equal(t, reflect.TypeOf(p1.Value), reflect.TypeOf(p2.Value))
switch p1.Value.(type) {
case *core.Scalar_Primitive:
EqualPrimitive(t, p1.GetPrimitive(), p2.GetPrimitive())
default:
assert.FailNow(t, "Not yet implemented for types %v", reflect.TypeOf(p1.Value))
}
}
func EqualLiterals(t *testing.T, l1 *core.Literal, l2 *core.Literal) {
if !assert.Equal(t, l1 == nil, l2 == nil) {
assert.FailNow(t, "One of the values is nil")
}
if l1 == nil {
return
}
assert.Equal(t, reflect.TypeOf(l1.Value), reflect.TypeOf(l2.Value))
switch l1.Value.(type) {
case *core.Literal_Scalar:
EqualScalar(t, l1.GetScalar(), l2.GetScalar())
case *core.Literal_Map:
EqualLiteralMap(t, l1.GetMap(), l2.GetMap())
default:
assert.FailNow(t, "Not supported test type")
}
}
func EqualLiteralMap(t *testing.T, l1 *core.LiteralMap, l2 *core.LiteralMap) {
if assert.NotNil(t, l1, "l1 is nil") && assert.NotNil(t, l2, "l2 is nil") {
assert.Equal(t, len(l1.Literals), len(l2.Literals))
for k, v := range l1.Literals {
actual, ok := l2.Literals[k]
assert.True(t, ok)
EqualLiterals(t, v, actual)
}
}
}
func EqualLiteralCollection(t *testing.T, l1 *core.LiteralCollection, l2 *core.LiteralCollection) {
if assert.NotNil(t, l2) {
assert.Equal(t, len(l1.Literals), len(l2.Literals))
for i, v := range l1.Literals {
EqualLiterals(t, v, l2.Literals[i])
}
}
}