-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
74 lines (61 loc) · 1.55 KB
/
api_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package mockhttp
import (
"testing"
assertions "github.com/stretchr/testify/assert"
)
type MockT struct {
t *testing.T
errorOccurred bool
fatalOccurred bool
}
func NewTestingMock(t *testing.T) *MockT {
return &MockT{
t: t,
errorOccurred: false,
fatalOccurred: false,
}
}
func (testState *MockT) Error(args ...interface{}) {
_ = args
testState.errorOccurred = true
}
func (testState *MockT) Errorf(format string, args ...interface{}) {
_, _ = format, args
testState.errorOccurred = true
}
func (testState *MockT) Fatalf(format string, args ...interface{}) {
_, _ = format, args
testState.fatalOccurred = true
}
func (testState *MockT) Fatal(args ...interface{}) {
_ = args
testState.fatalOccurred = true
}
func (testState *MockT) assertDidNotFailed() {
if testState.errorOccurred {
testState.t.Error("unexpected failure with error")
}
if testState.fatalOccurred {
testState.t.Error("unexpected failure with fatal")
}
}
func (testState *MockT) assertFailedWithError() {
if !testState.errorOccurred {
testState.t.Error("an error was expected to occur but did not")
}
}
func (testState *MockT) assertFailedWithFatal() {
if !testState.fatalOccurred {
testState.t.Error("a fatal was expected to occur but did not")
}
}
func TestApiUrl(t *testing.T) {
t.Parallel()
// Arrange
mockedAPI := API(NewTestingMock(t))
defer func() { mockedAPI.Close() }()
// Assert
assert := assertions.New(t)
assert.Equal(mockedAPI.testServer.URL, mockedAPI.GetURL().String())
assert.Equal(mockedAPI.GetURL().Host, mockedAPI.GetHost())
}