-
Notifications
You must be signed in to change notification settings - Fork 1
/
letters_proof_of_ids_test.go
45 lines (38 loc) · 1.16 KB
/
letters_proof_of_ids_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
43
44
45
package gocancel
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestLettersService_DownloadProofOfID(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/api/v1/letters/a/proof_of_ids/b", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeLetterProofOfID)
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename=proof.png")
fmt.Fprint(w, "Hello World")
})
ctx := context.Background()
reader, _, err := client.Letters.DownloadProofOfID(ctx, "a", "b")
if err != nil {
t.Fatalf("Letters.DownloadProofOfID returned error: %v", err)
}
content, err := ioutil.ReadAll(reader)
if err != nil {
t.Errorf("Letters.DownloadProofOfID returned bad reader: %v", err)
}
want := []byte("Hello World")
if !bytes.Equal(content, want) {
t.Errorf("Letters.DownloadProofOfID returned %+v, want %+v", content, want)
}
const methodName = "DownloadProofOfID"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Letters.DownloadProofOfID(ctx, "\n", "\n")
return err
})
}