-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrequests_test.go
More file actions
46 lines (39 loc) · 1.3 KB
/
requests_test.go
File metadata and controls
46 lines (39 loc) · 1.3 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
package tinybird_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/the-hotels-network/go-tinybird"
)
func newRequest(workspaceName, pipeName, alias, responseData string) tinybird.Request {
return tinybird.Request{
Pipe: tinybird.Pipe{
Name: pipeName,
Alias: alias,
Workspace: tinybird.Workspace{
Name: workspaceName,
},
},
Before: func(r *tinybird.Request) bool {
r.Response = tinybird.Response{
Body: responseData,
}
return true
},
}
}
func TestMultipleRequestsSuccess(t *testing.T) {
rs := tinybird.Requests{}
rs.Add(newRequest("workspace1", "pipe1", "alias1", `{"id":1}`))
rs.Add(newRequest("workspace2", "pipe2", "alias2", `{"id":2}`))
rs.Add(newRequest("workspace2", "pipe2", "alias3", `{"id":2}`))
rs.Execute()
assert.Len(t, rs, 3)
assert.Equal(t, rs[0].Pipe.Name, rs.Get("workspace1", "pipe1").Pipe.Name)
assert.Equal(t, rs[2].Pipe.Name, rs.GetByAlias("workspace2", "pipe2", "alias3").Pipe.Name)
assert.Empty(t, rs.Get("random-workspace", "random-pipe").Pipe.Name)
assert.Empty(t, rs.GetByAlias("random-workspace", "random-pipe", "random-alias").Pipe.Name)
assert.Equal(t, `{"id":1}`, rs[0].Response.Body)
assert.Equal(t, `{"id":2}`, rs[1].Response.Body)
assert.GreaterOrEqual(t, rs.Duration(), time.Duration(0).Nanoseconds())
}