1
17
18 package bootstrap
19
20 import "testing"
21
22 func Test_percentEncode(t *testing.T) {
23 tests := []struct {
24 name string
25 target string
26 want string
27 }{
28 {
29 name: "normal name",
30 target: "server.example.com",
31 want: "server.example.com",
32 },
33 {
34 name: "ipv4",
35 target: "0.0.0.0:8080",
36 want: "0.0.0.0:8080",
37 },
38 {
39 name: "ipv6",
40 target: "[::1]:8080",
41 want: "%5B::1%5D:8080",
42 },
43 {
44 name: "/ should not be percent encoded",
45 target: "my/service/region",
46 want: "my/service/region",
47 },
48 }
49 for _, tt := range tests {
50 t.Run(tt.name, func(t *testing.T) {
51 if got := percentEncode(tt.target); got != tt.want {
52 t.Errorf("percentEncode() = %v, want %v", got, tt.want)
53 }
54 })
55 }
56 }
57
58 func TestPopulateResourceTemplate(t *testing.T) {
59 tests := []struct {
60 name string
61 template string
62 target string
63 want string
64 }{
65 {
66 name: "no %s",
67 template: "/name/template",
68 target: "[::1]:8080",
69 want: "/name/template",
70 },
71 {
72 name: "with %s, no xdstp: prefix, ipv6",
73 template: "/name/template/%s",
74 target: "[::1]:8080",
75 want: "/name/template/[::1]:8080",
76 },
77 {
78 name: "with %s, with xdstp: prefix",
79 template: "xdstp://authority.com/%s",
80 target: "0.0.0.0:8080",
81 want: "xdstp://authority.com/0.0.0.0:8080",
82 },
83 {
84 name: "with %s, with xdstp: prefix, and ipv6",
85 template: "xdstp://authority.com/%s",
86 target: "[::1]:8080",
87 want: "xdstp://authority.com/%5B::1%5D:8080",
88 },
89 }
90 for _, tt := range tests {
91 t.Run(tt.name, func(t *testing.T) {
92 if got := PopulateResourceTemplate(tt.template, tt.target); got != tt.want {
93 t.Errorf("PopulateResourceTemplate() = %v, want %v", got, tt.want)
94 }
95 })
96 }
97 }
98
View as plain text