-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_test.go
153 lines (141 loc) · 3.23 KB
/
source_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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package gstreamer
import (
"fmt"
"testing"
"gopkg.in/sensorbee/sensorbee.v0/bql"
"gopkg.in/sensorbee/sensorbee.v0/core"
"gopkg.in/sensorbee/sensorbee.v0/data"
)
func TestCreateRawSource(t *testing.T) {
t.Run("valid cases", func(t *testing.T) {
cs := []map[string]interface{}{
{
"pipeline": "videotestsrc ! appsink param=1",
"format": "jpeg",
},
{
"pipeline": "videotestsrc ! appsink",
"format": "jpeg",
"width": 640,
"height": 480,
},
{
"pipeline": "videotestsrc ! appsink",
"format": "raw",
"width": 640,
"height": 480,
"color_model": "bgr",
},
}
for i, c := range cs {
t.Run(fmt.Sprint("case", i), func(t *testing.T) {
m, err := data.NewMap(c)
if err != nil {
t.Fatal("can't convert a map:", c)
}
s, err := createRawSource(&bql.IOParams{}, m)
if err != nil {
t.Fatal("creating a source failed:", err)
}
if s.pipeline != c["pipeline"].(string) {
t.Error("pipeline isn't set")
}
if s.format != c["format"].(string) {
t.Error("format isn't set")
}
switch s.format {
case "raw":
if s.width != c["width"].(int) {
t.Error("width isn't set")
}
if s.height != c["height"].(int) {
t.Error("height isn't set")
}
if s.format == "raw" && s.colorModel != c["color_model"].(string) {
t.Error("color_model isn't set")
}
}
})
}
})
t.Run("invalid cases", func(t *testing.T) {
t.Run("general", func(t *testing.T) {
cs := []struct {
n string
m map[string]interface{}
}{
{
n: "missing pipeline",
m: map[string]interface{}{
"format": "jpeg",
},
},
{
n: "missing format",
m: map[string]interface{}{
"pipeline": "videotestsrc ! appsink",
},
},
{
n: "unsupported format",
m: map[string]interface{}{
"pipeline": "videotestsrc ! appsink",
"format": "png",
},
},
{ // this is already tested in data.Decode. So, only this is ok.
n: "invalid value type",
m: map[string]interface{}{
"pipeline": "videotestsrc ! appsink",
"format": 1,
},
},
}
for _, c := range cs {
t.Run(c.n, func(t *testing.T) {
m, err := data.NewMap(c.m)
if err != nil {
t.Fatal("can't convert a map:", c.m)
}
_, err = CreateRawSource(core.NewContext(nil), &bql.IOParams{}, m)
if err == nil {
t.Error("CreateRawSource didn't fail")
}
})
}
})
t.Run("raw", func(t *testing.T) {
cs := []struct {
n string
missing string
}{
{
n: "missing width",
missing: "width",
},
{
n: "missing height",
missing: "height",
},
{
n: "unsupported format",
missing: "color_model",
},
}
for _, c := range cs {
m := data.Map{
"pipeline": data.String("videotestsrc ! appsink"),
"format": data.String("raw"),
"width": data.Int(640),
"height": data.Int(480),
"color_model": data.String("bgr"),
}
delete(m, c.missing)
_, err := CreateRawSource(core.NewContext(nil), &bql.IOParams{}, m)
if err == nil {
t.Error("CreateRawSource didn't fail:", c.n)
}
}
})
})
}