MCPcopy
hub / github.com/syncthing/syncthing / TestHTTPGetIndex

Function TestHTTPGetIndex

test/http_test.go:24–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestHTTPGetIndex(t *testing.T) {
25 p := startInstance(t, 2)
26 defer checkedStop(t, p)
27
28 // Check for explicit index.html
29
30 res, err := http.Get("http://localhost:8082/index.html")
31 if err != nil {
32 t.Fatal(err)
33 }
34 if res.StatusCode != 200 {
35 t.Errorf("Status %d != 200", res.StatusCode)
36 }
37 bs, err := io.ReadAll(res.Body)
38 if err != nil {
39 t.Fatal(err)
40 }
41 if len(bs) < 1024 {
42 t.Errorf("Length %d < 1024", len(bs))
43 }
44 if !bytes.Contains(bs, []byte("</html>")) {
45 t.Error("Incorrect response")
46 }
47 if res.Header.Get("Set-Cookie") == "" {
48 t.Error("No set-cookie header")
49 }
50 res.Body.Close()
51
52 // Check for implicit index.html
53
54 res, err = http.Get("http://localhost:8082/")
55 if err != nil {
56 t.Fatal(err)
57 }
58 if res.StatusCode != 200 {
59 t.Errorf("Status %d != 200", res.StatusCode)
60 }
61 bs, err = io.ReadAll(res.Body)
62 if err != nil {
63 t.Fatal(err)
64 }
65 if len(bs) < 1024 {
66 t.Errorf("Length %d < 1024", len(bs))
67 }
68 if !bytes.Contains(bs, []byte("</html>")) {
69 t.Error("Incorrect response")
70 }
71 if res.Header.Get("Set-Cookie") == "" {
72 t.Error("No set-cookie header")
73 }
74 res.Body.Close()
75}
76
77func TestHTTPGetIndexAuth(t *testing.T) {
78 p := startInstance(t, 1)

Callers

nothing calls this directly

Calls 7

startInstanceFunction · 0.85
checkedStopFunction · 0.85
FatalMethod · 0.80
ContainsMethod · 0.80
GetMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected