Skip to content

Commit 4d6068e

Browse files
committed
Fix tests
1 parent 29928a1 commit 4d6068e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestOpen(t *testing.T) {
3535
require.ErrorContains(t, err, "invalid connection string: host url must have both host and port")
3636

3737
_, err = dgo.Open("dgraph://localhost:")
38-
require.ErrorContains(t, err, "missing port after port-separator colon")
38+
require.ErrorContains(t, err, "invalid connection string: missing port after port-separator colon")
3939

4040
_, err = dgo.Open("dgraph://localhost:9180?sslmode=verify-ca")
4141
require.ErrorContains(t, err, "first record does not look like a TLS handshake")
@@ -77,7 +77,7 @@ func TestOpen(t *testing.T) {
7777
require.ErrorContains(t, err, "invalid namespace ID: strconv.ParseUint: parsing \"root\": invalid syntax")
7878

7979
_, err = dgo.Open("dgraph://user:pass@localhost:9180?namespace=1")
80-
require.NoError(t, err)
80+
require.ErrorContains(t, err, "invalid username or password")
8181

8282
_, err = dgo.Open("dgraph://groot:password@localhost:9180")
8383
require.NoError(t, err)

open.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ func Open(connStr string) (*Dgraph, error) {
169169
if apiKey != "" && bearerToken != "" {
170170
return nil, errors.New("invalid connection string: both apikey and bearertoken cannot be provided")
171171
}
172-
if !strings.Contains(u.Host, ":") {
172+
if len(strings.Split(u.Host, ":")) != 2 {
173173
return nil, errors.New("invalid connection string: host url must have both host and port")
174174
}
175+
if strings.Split(u.Host, ":")[1] == "" {
176+
return nil, errors.New("invalid connection string: missing port after port-separator colon")
177+
}
175178

176179
opts := []ClientOption{}
177180
if apiKey != "" {
@@ -257,6 +260,11 @@ func NewRoundRobinClient(endpoints []string, opts ...ClientOption) (*Dgraph, err
257260
}
258261
}
259262

263+
if _, err := dc[0].CheckVersion(context.Background(), &api.Check{}); err != nil {
264+
d.Close()
265+
return nil, fmt.Errorf("failed to ping: %w", err)
266+
}
267+
260268
return d, nil
261269
}
262270

0 commit comments

Comments
 (0)