forked from brimdata/super
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_test.go
69 lines (66 loc) · 1.72 KB
/
value_test.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
package zed_test
import (
"testing"
"github.com/brimdata/zed"
"github.com/brimdata/zed/zcode"
"github.com/stretchr/testify/assert"
)
func TestValueValidate(t *testing.T) {
r := zed.NewValue(
zed.NewTypeRecord(0, []zed.Field{
zed.NewField("f", zed.NewTypeSet(0, zed.TypeString)),
}),
nil)
t.Run("set/error/duplicate-element", func(t *testing.T) {
var b zcode.Builder
b.BeginContainer()
b.Append([]byte("dup"))
b.Append([]byte("dup"))
// Don't normalize.
b.EndContainer()
r.Bytes = b.Bytes()
assert.EqualError(t, r.Validate(), "invalid ZNG: duplicate set element")
})
t.Run("set/error/unsorted-elements", func(t *testing.T) {
var b zcode.Builder
b.BeginContainer()
b.Append([]byte("a"))
b.Append([]byte("z"))
b.Append([]byte("b"))
// Don't normalize.
b.EndContainer()
r.Bytes = b.Bytes()
assert.EqualError(t, r.Validate(), "invalid ZNG: set elements not sorted")
})
t.Run("set/primitive-elements", func(t *testing.T) {
var b zcode.Builder
b.BeginContainer()
b.Append([]byte("dup"))
b.Append([]byte("dup"))
b.Append([]byte("z"))
b.Append([]byte("a"))
b.TransformContainer(zed.NormalizeSet)
b.EndContainer()
r.Bytes = b.Bytes()
assert.NoError(t, r.Validate())
})
t.Run("set/complex-elements", func(t *testing.T) {
var b zcode.Builder
b.BeginContainer()
for _, s := range []string{"dup", "dup", "z", "a"} {
b.BeginContainer()
b.Append([]byte(s))
b.EndContainer()
}
b.TransformContainer(zed.NormalizeSet)
b.EndContainer()
r := zed.NewValue(
zed.NewTypeRecord(0, []zed.Field{
zed.NewField("f", zed.NewTypeSet(0, zed.NewTypeRecord(0, []zed.Field{
zed.NewField("g", zed.TypeString),
}))),
}),
b.Bytes())
assert.NoError(t, r.Validate())
})
}