-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_service_test.go
70 lines (52 loc) · 1.55 KB
/
status_service_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
package client
import (
"context"
"net/http"
"testing"
"time"
"github.com/NdoleStudio/go-http-client/internal/helpers"
"github.com/stretchr/testify/assert"
)
func TestStatusService_Ok(t *testing.T) {
// Setup
t.Parallel()
// Arrange
client := New()
// Act
status, response, err := client.Status.Ok(context.Background())
// Assert
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode)
assert.Equal(t, &HTTPStatus{Code: 200, Description: "OK"}, status)
}
func TestBillsService_OkWithDelay(t *testing.T) {
// Setup
t.Parallel()
start := time.Now()
// Arrange
client := New(WithDelay(500))
// Act
status, response, err := client.Status.Ok(context.Background())
// Assert
assert.Nil(t, err)
assert.LessOrEqual(t, int64(100), time.Since(start).Milliseconds())
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode)
assert.Equal(t, &HTTPStatus{Code: 200, Description: "OK"}, status)
}
func TestBillsService_OkWithError(t *testing.T) {
// Setup
t.Parallel()
// Arrange
server := helpers.MakeTestServer(http.StatusInternalServerError, []byte("Internal Server Error"))
client := New(WithBaseURL(server.URL))
// Act
status, response, err := client.Status.Ok(context.Background())
// Assert
assert.NotNil(t, err)
assert.Nil(t, status)
assert.Equal(t, "500: Internal Server Error, Body: Internal Server Error", err.Error())
assert.Equal(t, http.StatusInternalServerError, response.HTTPResponse.StatusCode)
assert.Equal(t, "Internal Server Error", string(*response.Body))
// Teardown
server.Close()
}