Skip to content

Commit 942dc16

Browse files
author
gm0stache
committed
test: cover changes
1 parent fcb62ff commit 942dc16

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

pkg/client/dns.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"net"
99
"net/http"
10+
"net/netip"
1011
"sync"
1112
"time"
1213

@@ -109,9 +110,7 @@ func verifyCaddyReachable(ctx context.Context, m *pb.MachineInfo) error {
109110
eventID := fmt.Sprintf("Machine %s (%s)", m.Name, publicIP)
110111
pw.Event(progress.NewEvent(eventID, progress.Working, "Querying"))
111112

112-
httpFormattedIP := net.JoinHostPort(publicIP.String(), "")
113-
verifyURL := fmt.Sprintf("http://%s%s", httpFormattedIP, caddyconfig.VerifyPath)
114-
113+
verifyURL := getVerifyURL(publicIP)
115114
req, err := http.NewRequestWithContext(ctx, http.MethodGet, verifyURL, nil)
116115
if err != nil {
117116
pw.Event(progress.NewEvent(eventID, progress.Error, err.Error()))
@@ -172,6 +171,11 @@ func verifyCaddyReachable(ctx context.Context, m *pb.MachineInfo) error {
172171
}
173172
}
174173

174+
func getVerifyURL(publicIP netip.Addr) string {
175+
httpFormattedIP := net.JoinHostPort(publicIP.String(), "")
176+
return fmt.Sprintf("http://%s%s", httpFormattedIP, caddyconfig.VerifyPath)
177+
}
178+
175179
// unreachable creates a new Unreachable error event.
176180
func unreachable(id string) progress.Event {
177181
return progress.NewEvent(

pkg/client/dns_internal_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package client
2+
3+
import (
4+
"net/netip"
5+
"testing"
6+
)
7+
8+
func TestGetVerifyURL(t *testing.T) {
9+
tests := map[string]struct {
10+
ip netip.Addr
11+
want string
12+
}{
13+
"IPv4": {
14+
ip: netip.MustParseAddr("93.184.216.34"),
15+
want: "http://93.184.216.34:/.uncloud-verify",
16+
},
17+
"IPv6": {
18+
ip: netip.MustParseAddr("2001:db8::1"),
19+
want: "http://[2001:db8::1]:/.uncloud-verify",
20+
},
21+
}
22+
for name, tt := range tests {
23+
t.Run(name, func(t *testing.T) {
24+
if got := getVerifyURL(tt.ip); got != tt.want {
25+
t.Errorf("getVerifyURL() = %q, want %q", got, tt.want)
26+
}
27+
})
28+
}
29+
}

0 commit comments

Comments
 (0)