-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods_test.go
More file actions
61 lines (57 loc) · 1.58 KB
/
methods_test.go
File metadata and controls
61 lines (57 loc) · 1.58 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package lite
import (
"reflect"
"testing"
)
func Test_Add(t *testing.T) {
t.Run("Given Methods (list of HTTP methods)", func(t *testing.T) {
t.Run("method Add should add strings to a slice", func(t *testing.T) {
list := &Methods{}
list.Add("GET")
list.Add("POST")
list.Add("PUT")
if !reflect.DeepEqual(list, &Methods{"GET", "POST", "PUT"}) {
t.Errorf("list of methods is not valid: %v", list)
}
})
t.Run("method Add should ignore duplicates", func(t *testing.T) {
list := &Methods{}
list.Add("GET")
list.Add("GET")
list.Add("PUT")
if !reflect.DeepEqual(list, &Methods{"GET", "PUT"}) {
t.Errorf("list of methods is not valid: %v", list)
}
})
})
}
func Test_Join(t *testing.T) {
t.Run("Given Methods (list of HTTP methods)", func(t *testing.T) {
t.Run("method Join should convert slice to a string", func(t *testing.T) {
list := &Methods{}
list.Add("GET")
list.Add("POST")
list.Add("PUT")
if list.Join() != "GET,POST,PUT" {
t.Errorf("the result was expected to be \"GET,POST,PUT\" but was %q", list.Join())
}
})
})
}
func Test_Empty(t *testing.T) {
t.Run("Given Methods (list of HTTP methods)", func(t *testing.T) {
t.Run("method Empty should return true if list is empty", func(t *testing.T) {
list := &Methods{}
if list.Empty() != true {
t.Error("the result was expected to be true")
}
})
t.Run("method Empty should return false if list is not empty", func(t *testing.T) {
list := &Methods{}
list.Add("GET")
if list.Empty() != false {
t.Error("the result was expected to be false")
}
})
})
}