forked from getgauge/gauge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecCollection_test.go
49 lines (38 loc) · 1.3 KB
/
specCollection_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
package gauge
import (
"reflect"
"testing"
)
func TestSpecCollection(t *testing.T) {
s1 := &Specification{FileName: "filename1"}
s2 := &Specification{FileName: "filename2"}
s3 := &Specification{FileName: "filename3"}
collection := NewSpecCollection([]*Specification{s1, s2, s3}, false)
got := [][]*Specification{collection.Next(), collection.Next(), collection.Next()}
want := [][]*Specification{{s1}, {s2}, {s3}}
if !reflect.DeepEqual(want, got) {
t.Errorf("Spec Collection Failed\n\tWant: %v\n\t Got:%v", want, got)
}
}
func TestGroupSpecCollection(t *testing.T) {
s1 := &Specification{FileName: "filename1"}
s3 := &Specification{FileName: "filename3"}
collection := NewSpecCollection([]*Specification{s1, s3, s3}, true)
got := [][]*Specification{collection.Next(), collection.Next()}
want := [][]*Specification{{s1}, {s3, s3}}
if !reflect.DeepEqual(set(want), set(got)) {
t.Errorf("Spec Collection Failed\n\tWant: %v\n\t Got:%v", want, got)
}
for key, value := range got {
if value[0].FileName != want[key][0].FileName {
t.Errorf("Spec Collection order is not maintained\n\tWant: %v\n\t Got:%v", want[key], got[key])
}
}
}
func set(s [][]*Specification) map[int][]*Specification {
specs := make(map[int][]*Specification)
for _, sp := range s {
specs[len(sp)] = sp
}
return specs
}