blob: b0309c772996b8ee60999bd5f4f48477418efcc8 (
plain) (
blame)
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
|
// Copyright © 2022 siddharth ravikumar <s@ricketyspace.net>
// SPDX-License-Identifier: ISC
package client
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
"ricketyspace.net/peach/version"
)
func TestGet(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check user-agent header.
expectedUA := fmt.Sprintf("peach/%s peach.ricketyspace.net",
version.Version)
if r.Header.Get("User-Agent") != expectedUA {
t.Errorf("header: user agent: %v != %v",
r.Header.Get("User-Agent"), expectedUA)
return
}
// Check cache-control header.
if r.Header.Get("Cache-Control") != "max-age=0" {
t.Errorf("header: cache control: %v != max-age=0",
r.Header.Get("Cache-Control"))
return
}
fmt.Fprint(w, "OK")
}))
defer ts.Close()
res, err := Get(ts.URL)
if err != nil {
t.Errorf("get failed: %v", err)
return
}
_, err = io.ReadAll(res.Body)
if err != nil {
t.Errorf("response read failed: %v", err)
return
}
}
|