-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbids_test.go
More file actions
51 lines (44 loc) · 1.13 KB
/
Copy pathbids_test.go
File metadata and controls
51 lines (44 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
// Copyright 2023 Bill Nixon. All rights reserved.
// Use of this source code is governed by the license found in the LICENSE file.
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestBidsHandler(t *testing.T) {
testCases := []struct {
name string
method string
expectedStatus int
expectedInBody string
}{
{
name: "ValidGET",
method: http.MethodGet,
expectedStatus: http.StatusOK,
expectedInBody: "Items",
},
{
name: "InvalidMethod",
method: http.MethodPost,
expectedStatus: http.StatusMethodNotAllowed,
expectedInBody: "Method Not Allowed",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
r := httptest.NewRequest(tc.method, "/bids", nil)
w := httptest.NewRecorder()
app := AppForTest(t)
app.BidsHandler(w, r)
if w.Code != tc.expectedStatus {
t.Errorf("expected status %d but got %d", tc.expectedStatus, w.Code)
}
if !strings.Contains(w.Body.String(), tc.expectedInBody) {
t.Errorf("expected %q in body but got %q", tc.expectedInBody, w.Body)
}
})
}
}