-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhelper_test.go
59 lines (47 loc) · 1.25 KB
/
helper_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
package mux
import (
"errors"
"fmt"
"math/rand"
"testing"
)
func createRandomStringsCount() (pairs []string, count int) {
randNumber := rand.Intn(100-10) + 10
for i := 0; i < randNumber; i++ {
pairs = append(pairs, "dummy")
}
count = len(pairs)
return
}
func TestIsEvenPairs(t *testing.T) {
for i := 0; i <= 5; i++ {
pairs, count := createRandomStringsCount()
t.Run(fmt.Sprintf("Check pairs test (Count: %v)", count), func(t *testing.T) {
_, err := isEvenPairs(pairs...)
if err == nil && count%2 != 0 {
t.Error("Unexpected pairs count")
} else if err != nil && count%2 == 0 {
t.Error("Unexpected pairs count")
}
})
}
}
func TestConvertStringsToMap(t *testing.T) {
isEvenPairs := func(pairs ...string) (int, error) {
return 2, nil
}
pairs := []string{"content-type", "application/json"}
m, _ := convertStringsToMap(isEvenPairs, pairs...)
if value, ok := m["content-type"]; !ok || value != "application/json" {
t.Error("Unexpected pair")
}
}
func TestConvertStringsToMapError(t *testing.T) {
isEvenPairs := func(pairs ...string) (int, error) {
return 3, errors.New("Something went wrong")
}
pairs := []string{}
if _, err := convertStringsToMap(isEvenPairs, pairs...); err == nil {
t.Error("Unexpected nil error")
}
}