blob: a37f4e11054f627ff2ef429c111424a0b4b928d5 (
plain)
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
|
package client
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestEncode(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "response")
}))
defer server.Close()
client := CaesarClient{Endpoint: server.URL} // HL
var b bytes.Buffer
if err := client.EncodeMessage(&b, strings.NewReader("secret message")); err != nil {
t.Errorf("should not have gotten error: %v", err)
}
resp := b.String()
if resp != "response" {
t.Errorf("expected 'response' but got '%s'", resp)
}
}
func TestUserAgent(t *testing.T) {
var ua string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ua = r.Header.Get("user-agent")
}))
defer server.Close()
c := CaesarClient{Endpoint: server.URL}
if err := c.EncodeMessage(ioutil.Discard, strings.NewReader("secret message")); err != nil {
t.Errorf("expected no error but got %v", err)
}
expected := "caesar-client/1.0"
if ua != expected {
t.Errorf("expected user agent header %q but got %q", expected, ua)
}
}
|