Skip to content

Commit 997c250

Browse files
committed
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Use endpoint as default connection option (ADR-119)
1 parent 6ff3df0 commit 997c250

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

ably/export_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func GetEndpointFallbackHosts(endpoint string) []string {
1616
return getEndpointFallbackHosts(endpoint)
1717
}
1818

19-
func (opts *clientOptions) GetEndpoint() string {
19+
func (opts *clientOptions) GetHostname() string {
2020
return opts.getHostname()
2121
}
2222

ably/options_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestInternetConnectionCheck_RTN17c(t *testing.T) {
7171
func TestHosts_REC1(t *testing.T) {
7272
t.Run("REC1a with default options", func(t *testing.T) {
7373
clientOptions := ably.NewClientOptions()
74-
assert.Equal(t, "main.realtime.ably.net", clientOptions.GetEndpoint())
74+
assert.Equal(t, "main.realtime.ably.net", clientOptions.GetHostname())
7575
assert.False(t, clientOptions.NoTLS)
7676
port, isDefaultPort := clientOptions.ActivePort()
7777
assert.Equal(t, 443, port)
@@ -82,7 +82,7 @@ func TestHosts_REC1(t *testing.T) {
8282

8383
t.Run("REC1b with endpoint as a custom routing policy name", func(t *testing.T) {
8484
clientOptions := ably.NewClientOptions(ably.WithEndpoint("acme"))
85-
assert.Equal(t, "acme.realtime.ably.net", clientOptions.GetEndpoint())
85+
assert.Equal(t, "acme.realtime.ably.net", clientOptions.GetHostname())
8686
assert.False(t, clientOptions.NoTLS)
8787
port, isDefaultPort := clientOptions.ActivePort()
8888
assert.Equal(t, 443, port)
@@ -93,7 +93,7 @@ func TestHosts_REC1(t *testing.T) {
9393

9494
t.Run("REC1b3 with endpoint as a nonprod routing policy name", func(t *testing.T) {
9595
clientOptions := ably.NewClientOptions(ably.WithEndpoint("nonprod:acme"))
96-
assert.Equal(t, "acme.realtime.ably-nonprod.net", clientOptions.GetEndpoint())
96+
assert.Equal(t, "acme.realtime.ably-nonprod.net", clientOptions.GetHostname())
9797
assert.False(t, clientOptions.NoTLS)
9898
port, isDefaultPort := clientOptions.ActivePort()
9999
assert.Equal(t, 443, port)
@@ -104,7 +104,7 @@ func TestHosts_REC1(t *testing.T) {
104104

105105
t.Run("REC1b2 with endpoint as a fqdn with no fallbackHosts specified", func(t *testing.T) {
106106
clientOptions := ably.NewClientOptions(ably.WithEndpoint("foo.example.com"))
107-
assert.Equal(t, "foo.example.com", clientOptions.GetEndpoint())
107+
assert.Equal(t, "foo.example.com", clientOptions.GetHostname())
108108
assert.False(t, clientOptions.NoTLS)
109109
port, isDefaultPort := clientOptions.ActivePort()
110110
assert.Equal(t, 443, port)
@@ -116,7 +116,7 @@ func TestHosts_REC1(t *testing.T) {
116116

117117
t.Run("REC1b2 REC2a2 with endpoint as a fqdn with fallbackHosts specified", func(t *testing.T) {
118118
clientOptions := ably.NewClientOptions(ably.WithEndpoint("foo.example.com"), ably.WithFallbackHosts([]string{"fallback.foo.example.com"}))
119-
assert.Equal(t, "foo.example.com", clientOptions.GetEndpoint())
119+
assert.Equal(t, "foo.example.com", clientOptions.GetHostname())
120120
assert.False(t, clientOptions.NoTLS)
121121
port, isDefaultPort := clientOptions.ActivePort()
122122
assert.Equal(t, 443, port)
@@ -129,7 +129,7 @@ func TestHosts_REC1(t *testing.T) {
129129
t.Run("legacy support", func(t *testing.T) {
130130
t.Run("REC1c with production environment", func(t *testing.T) {
131131
clientOptions := ably.NewClientOptions(ably.WithEnvironment("production"))
132-
assert.Equal(t, "main.realtime.ably.net", clientOptions.GetEndpoint())
132+
assert.Equal(t, "main.realtime.ably.net", clientOptions.GetHostname())
133133
assert.False(t, clientOptions.NoTLS)
134134
port, isDefaultPort := clientOptions.ActivePort()
135135
assert.Equal(t, 443, port)
@@ -140,7 +140,7 @@ func TestHosts_REC1(t *testing.T) {
140140

141141
t.Run("REC1c with sandbox environment", func(t *testing.T) {
142142
clientOptions := ably.NewClientOptions(ably.WithEnvironment("sandbox"))
143-
assert.Equal(t, "sandbox.realtime.ably-nonprod.net", clientOptions.GetEndpoint())
143+
assert.Equal(t, "sandbox.realtime.ably-nonprod.net", clientOptions.GetHostname())
144144
assert.False(t, clientOptions.NoTLS)
145145
port, isDefaultPort := clientOptions.ActivePort()
146146
assert.Equal(t, 443, port)
@@ -151,7 +151,7 @@ func TestHosts_REC1(t *testing.T) {
151151

152152
t.Run("REC1c with custom environment", func(t *testing.T) {
153153
clientOptions := ably.NewClientOptions(ably.WithEnvironment("acme"))
154-
assert.Equal(t, "acme.realtime.ably.net", clientOptions.GetEndpoint())
154+
assert.Equal(t, "acme.realtime.ably.net", clientOptions.GetHostname())
155155
assert.False(t, clientOptions.NoTLS)
156156
port, isDefaultPort := clientOptions.ActivePort()
157157
assert.Equal(t, 443, port)
@@ -162,7 +162,7 @@ func TestHosts_REC1(t *testing.T) {
162162

163163
t.Run("REC1c REC2a1 with custom environment and fallbackHostUseDefault", func(t *testing.T) {
164164
clientOptions := ably.NewClientOptions(ably.WithEnvironment("acme"), ably.WithFallbackHostsUseDefault(true))
165-
assert.Equal(t, "acme.realtime.ably.net", clientOptions.GetEndpoint())
165+
assert.Equal(t, "acme.realtime.ably.net", clientOptions.GetHostname())
166166
assert.False(t, clientOptions.NoTLS)
167167
port, isDefaultPort := clientOptions.ActivePort()
168168
assert.Equal(t, 443, port)
@@ -177,7 +177,7 @@ func TestHosts_REC1(t *testing.T) {
177177
ably.WithPort(8080),
178178
ably.WithTLSPort(8081),
179179
)
180-
assert.Equal(t, "local.realtime.ably.net", clientOptions.GetEndpoint())
180+
assert.Equal(t, "local.realtime.ably.net", clientOptions.GetHostname())
181181
assert.False(t, clientOptions.NoTLS)
182182
port, isDefaultPort := clientOptions.ActivePort()
183183
assert.Equal(t, 8081, port)
@@ -188,7 +188,7 @@ func TestHosts_REC1(t *testing.T) {
188188

189189
t.Run("REC1d1 with custom restHost", func(t *testing.T) {
190190
clientOptions := ably.NewClientOptions(ably.WithRESTHost("test.org"))
191-
assert.Equal(t, "test.org", clientOptions.GetEndpoint())
191+
assert.Equal(t, "test.org", clientOptions.GetHostname())
192192
assert.False(t, clientOptions.NoTLS)
193193
port, isDefaultPort := clientOptions.ActivePort()
194194
assert.Equal(t, 443, port)
@@ -199,7 +199,7 @@ func TestHosts_REC1(t *testing.T) {
199199

200200
t.Run("REC1d2 with custom realtimeHost", func(t *testing.T) {
201201
clientOptions := ably.NewClientOptions(ably.WithRealtimeHost("ws.test.org"))
202-
assert.Equal(t, "ws.test.org", clientOptions.GetEndpoint())
202+
assert.Equal(t, "ws.test.org", clientOptions.GetHostname())
203203
assert.False(t, clientOptions.NoTLS)
204204
port, isDefaultPort := clientOptions.ActivePort()
205205
assert.Equal(t, 443, port)
@@ -210,7 +210,7 @@ func TestHosts_REC1(t *testing.T) {
210210

211211
t.Run("REC1d with custom restHost and realtimeHost", func(t *testing.T) {
212212
clientOptions := ably.NewClientOptions(ably.WithRealtimeHost("ws.test.org"), ably.WithRESTHost("test.org"))
213-
assert.Equal(t, "test.org", clientOptions.GetEndpoint())
213+
assert.Equal(t, "test.org", clientOptions.GetHostname())
214214
assert.False(t, clientOptions.NoTLS)
215215
port, isDefaultPort := clientOptions.ActivePort()
216216
assert.Equal(t, 443, port)
@@ -224,7 +224,7 @@ func TestHosts_REC1(t *testing.T) {
224224
ably.WithRealtimeHost("ws.test.org"),
225225
ably.WithRESTHost("test.org"),
226226
ably.WithFallbackHostsUseDefault(true))
227-
assert.Equal(t, "test.org", clientOptions.GetEndpoint())
227+
assert.Equal(t, "test.org", clientOptions.GetHostname())
228228
assert.False(t, clientOptions.NoTLS)
229229
port, isDefaultPort := clientOptions.ActivePort()
230230
assert.Equal(t, 443, port)
@@ -236,7 +236,7 @@ func TestHosts_REC1(t *testing.T) {
236236

237237
t.Run("REC2a with fallbackHosts", func(t *testing.T) {
238238
clientOptions := ably.NewClientOptions(ably.WithFallbackHosts([]string{"a.example.com", "b.example.com"}))
239-
assert.Equal(t, "main.realtime.ably.net", clientOptions.GetEndpoint())
239+
assert.Equal(t, "main.realtime.ably.net", clientOptions.GetHostname())
240240
assert.False(t, clientOptions.NoTLS)
241241
port, isDefaultPort := clientOptions.ActivePort()
242242
assert.Equal(t, 443, port)

ablytest/sandbox.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"net/url"
1414
"os"
1515
"path"
16-
"regexp"
16+
"strings"
1717
"syscall"
1818
"time"
1919

@@ -259,11 +259,10 @@ func (app *Sandbox) Options(opts ...ably.ClientOption) []ably.ClientOption {
259259
return appOpts
260260
}
261261

262-
var nonprodRegexp = regexp.MustCompile(`^nonprod:(.*)$`)
263-
264262
func (app *Sandbox) URL(paths ...string) string {
265-
if match := nonprodRegexp.FindStringSubmatch(app.Endpoint); match != nil {
266-
return fmt.Sprintf("https://%s.realtime.ably-nonprod.net/%s", match[1], path.Join(paths...))
263+
if strings.HasPrefix(app.Endpoint, "nonprod:") {
264+
namespace := strings.TrimPrefix(app.Endpoint, "nonprod:")
265+
return fmt.Sprintf("https://%s.realtime.ably-nonprod.net/%s", namespace, path.Join(paths...))
267266
}
268267

269268
return fmt.Sprintf("https://%s.realtime.ably.net/%s", app.Endpoint, path.Join(paths...))

0 commit comments

Comments
 (0)