-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgmapsign_test.go
54 lines (41 loc) · 1.68 KB
/
gmapsign_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
46
47
48
49
50
51
52
53
54
package gmapsign
import (
"bytes"
"strings"
"testing"
)
func TestSign(t *testing.T) {
url := "https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&client=myclient"
key, err := DecodeSigningKey("bXlrZXk=")
if err != nil {
t.Errorf("decoding signing key: %w", err)
}
got, err := Sign(url, key)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
exp := "https://maps.googleapis.com/maps/api/staticmap?center=40.714%2C+-73.998&client=myclient&size=400x400&zoom=12&signature=C1UG9w-v41q7i1lISpZsw1xzOV8="
if got != exp {
t.Errorf("expected: %q, got: %q", exp, got)
}
}
func TestPipeline(t *testing.T) {
key, err := DecodeSigningKey("bXlrZXk=")
if err != nil {
t.Errorf("decoding signing key: %w", err)
}
in := strings.NewReader(`
https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&client=myclient
https://maps.googleapis.com/maps/api/distancematrix/json?departure_time=now&destinations=38.62288639085796%2C-9.223203416168769&mode=driving&origins=38.62288639085796%2C-9.223203416168769&units=metric`)
out := &bytes.Buffer{}
err = Pipeline(in, out, key)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
exp := `https://maps.googleapis.com/maps/api/staticmap?center=40.714%2C+-73.998&client=myclient&size=400x400&zoom=12&signature=C1UG9w-v41q7i1lISpZsw1xzOV8=
https://maps.googleapis.com/maps/api/distancematrix/json?departure_time=now&destinations=38.62288639085796%2C-9.223203416168769&mode=driving&origins=38.62288639085796%2C-9.223203416168769&units=metric&signature=kGApffVXsWUUbRv_lw3UnrejoOI=
`
if out.String() != exp {
t.Errorf("expected: %q, got: %q", exp, out.String())
}
}