-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_builder_test.go
More file actions
60 lines (47 loc) · 1.13 KB
/
Copy pathrequest_builder_test.go
File metadata and controls
60 lines (47 loc) · 1.13 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
package requestbuilder
import (
"errors"
"testing"
)
func TestRequestBuilderNilCondition(t *testing.T) {
builder := NewRequestBuilder().WithBody("")
builder.Build()
builder.WithHeaders(nil)
builder.WithHeader("hi", "hello")
}
func TestDefaultsFailWithoutUrlInRequest(t *testing.T) {
_, err := NewRequestBuilder().Build()
if err == nil {
t.Fail()
}
if !errors.Is(err, ErrNoUrlFound) {
t.Fail()
}
}
func TestDefaultFailNoSupportedMethod(t *testing.T) {
_, err := NewRequestBuilder().
WithUrl("something-url.com").
WithMethod("HEHE").
Build()
if !errors.Is(err, ErrNoSupportedMethod) {
t.Fail()
}
}
func TestDefaultsInRequest(t *testing.T) {
defaultReqeust, err := NewRequestBuilder().WithUrl("something.com").Build()
if err != nil {
t.Fail()
}
if defaultReqeust.GetMethod() != "GET" {
t.Error("Default method expected: GET found: ", defaultReqeust.GetMethod())
t.Fail()
}
if defaultReqeust.GetTimeout() != 30 {
t.Error("Default timeout expected: 30 found:", defaultReqeust.GetTimeout())
t.Fail()
}
if defaultReqeust.GetHeaders() == nil {
t.Error("Default headers should not be nil")
t.Fail()
}
}