-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreporter_test.go
52 lines (42 loc) · 1.1 KB
/
reporter_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
package main
import (
"encoding/json"
"reflect"
"testing"
)
func TestParseChannelsWhenThereIsANewReport(t *testing.T) {
reportsChan := make(chan *TestJob)
r := NewReporter(reportsChan, make(chan []int))
go func() {
reportsChan <- &TestJob{Id: 123}
}()
r.ParseChannels()
if len(r.reports) < 1 || r.reports[0].Id != 123 {
t.Error("It should put the new TestJob in the reports list")
}
}
func TestParseChannelsWhenActiveServerIsDone(t *testing.T) {
reportsChan := make(chan *TestJob)
r := NewReporter(reportsChan, make(chan []int))
r.activeSenders = 2
go func() {
r.activeSenderDone <- true
}()
r.ParseChannels()
if r.activeSenders != 1 {
t.Error("It should decrement activeSenders")
}
}
func TestDeleteTestRunIds(t *testing.T) {
reportsChan := make(chan *TestJob)
r := NewReporter(reportsChan, make(chan []int))
responseText := `{"delete_test_runs":[1976]}`
var result interface{}
err := json.Unmarshal(([]byte)(responseText), &result)
if err != nil {
t.Error(err.Error())
}
if !reflect.DeepEqual(r.deleteTestRunIds(result), []int{1976}) {
t.Error("It should return []int{1976}")
}
}