master
go 66 lines 1.37 KB
Raw
1 package pin
2
3 import (
4 "testing"
5 )
6
7 func TestNormalizeEndpoint(t *testing.T) {
8 cases := []struct {
9 in string
10 err string
11 out string
12 }{
13 {
14 in: "https://1.example.com",
15 err: "",
16 out: "https://1.example.com",
17 },
18 {
19 in: "https://2.example.com/",
20 err: "",
21 out: "https://2.example.com",
22 },
23 {
24 in: "https://3.example.com/pins/",
25 err: "service endpoint should be provided without the /pins suffix",
26 out: "",
27 },
28 {
29 in: "https://4.example.com/pins",
30 err: "service endpoint should be provided without the /pins suffix",
31 out: "",
32 },
33 {
34 in: "https://5.example.com/./some//nonsense/../path/../path/",
35 err: "",
36 out: "https://5.example.com/some/path",
37 },
38 {
39 in: "https://6.example.com/endpoint/?query=val",
40 err: "service endpoint should be provided without any query parameters",
41 out: "",
42 },
43 {
44 in: "http://192.168.0.5:45000/",
45 err: "",
46 out: "http://192.168.0.5:45000",
47 },
48 {
49 in: "foo://4.example.com/pins",
50 err: "service endpoint must be a valid HTTP URL",
51 out: "",
52 },
53 }
54
55 for _, tc := range cases {
56 out, err := normalizeEndpoint(tc.in)
57 if err != nil && tc.err != err.Error() {
58 t.Errorf("unexpected error for %q: expected %q; got %q", tc.in, tc.err, err)
59 continue
60 }
61 if out != tc.out {
62 t.Errorf("unexpected endpoint for %q: expected %q; got %q", tc.in, tc.out, out)
63 continue
64 }
65 }
66 }