forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_load_test.go
42 lines (32 loc) · 949 Bytes
/
simple_load_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
package main
import (
"fmt"
"io"
"log"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestWriteThenReadToEof(t *testing.T) {
ts := StartServer(t, false)
defer ts.Close()
logContents := "not\na\nvery\nlong\nlog"
client := http.Client{}
// first write until EOF
body := io.NopCloser(strings.NewReader(logContents))
req, err := http.NewRequest("PUT", fmt.Sprintf("http://127.0.0.1:%d/log", ts.PutPort()), body)
require.NoError(t, err)
res, err := client.Do(req)
require.NoError(t, err)
log.Printf("%#v", res)
require.Equal(t, 201, res.StatusCode)
// now contact the GET port and read until EOF
res, err = http.Get(fmt.Sprintf("http://127.0.0.1:%d/log/7_3HoMEbQau1Qlzwx-JZgg", ts.GetPort()))
require.NoError(t, err)
log.Printf("%#v", res)
require.Equal(t, 200, res.StatusCode)
resBody, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.Equal(t, logContents, string(resBody))
}