-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrands_test.go
66 lines (59 loc) · 1.43 KB
/
errands_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
package errands
import (
"testing"
"time"
schemas "github.com/polygon-io/errands-server/schemas"
log "github.com/sirupsen/logrus"
)
func TestGetErrands(t *testing.T) {
api := New("http://localhost:5555")
errands, err := api.GetErrands()
if err != nil {
t.Error(err)
}
log.Println("Got Errands:", errands.Results)
}
var createdId string
func TestCreateErrand(t *testing.T) {
api := New("http://localhost:5555")
errand := &schemas.Errand{}
errand.Name = "Test Errand"
errand.Type = "tester"
// errand.Data = map[string]interface{}{
// "testkey": "testvalue",
// }
errandRes, err := api.CreateErrand(errand)
if err != nil {
t.Error(err)
}
log.Println("Created Errand:", errandRes)
createdId = errandRes.Results.ID
}
func TestProcessErrand(t *testing.T) {
TestCreateErrand(t)
api := New("http://localhost:5555")
wait := make(chan int, 2)
fn := func(errand *schemas.Errand) (map[string]interface{}, error) {
log.Println("Processing:", errand.Name, " - ID: ", errand.ID)
time.Sleep(5 * time.Second)
wait <- 1
return map[string]interface{}{
"results": "OK",
}, nil
}
processor, err := api.NewProcessor("tester", 1, fn)
if err != nil {
t.Error(err)
}
<-wait
<-wait
log.Println("Processed Errand..", processor)
}
func TestDeleteErrand(t *testing.T) {
api := New("http://localhost:5555")
errandRes, err := api.DeleteErrand(createdId)
if err != nil {
t.Error(err)
}
log.Println("Deleted Errand:", errandRes)
}