blob: 5aa70810998be7aa5c699d5a8e0c9e5e90837837 (
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
48
49
50
51
52
53
54
|
// 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
}
// Check accept header.
if r.Header.Get("Accept") != "application/geo+json" {
t.Errorf("header: accept: %v != application/geo+json",
r.Header.Get("Accept"))
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
}
}
|