-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: heanlan <[email protected]>
- Loading branch information
Showing
2 changed files
with
25 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,56 +334,46 @@ func TestUpdateCH(t *testing.T) { | |
|
||
func TestParseDatabaseURL(t *testing.T) { | ||
testcases := []struct { | ||
url string | ||
expectedProto protocol | ||
expectedAddr string | ||
expectedErr error | ||
url string | ||
expectedProto protocol | ||
expectedAddr string | ||
expectedErrMsg string | ||
}{ | ||
{ | ||
url: "tcp://127.0.0.1:9000", | ||
expectedProto: protocolTCP, | ||
expectedAddr: "127.0.0.1:9000", | ||
expectedErr: nil, | ||
url: "tcp://127.0.0.1:9000", | ||
expectedProto: protocolTCP, | ||
expectedAddr: "127.0.0.1:9000", | ||
expectedErrMsg: "", | ||
}, | ||
{ | ||
url: "abc://127.0.0.1:9000", | ||
expectedProto: protocolUnknown, | ||
expectedAddr: "", | ||
expectedErr: fmt.Errorf("connection over abc transport protocol is not supported"), | ||
url: "abc://127.0.0.1:9000", | ||
expectedErrMsg: "connection over abc transport protocol is not supported", | ||
}, | ||
{ | ||
url: "127.0.0.1:9000", | ||
expectedProto: protocolUnknown, | ||
expectedAddr: "", | ||
expectedErr: fmt.Errorf("failed to parse ClickHouse database URL"), | ||
url: "127.0.0.1:9000", | ||
expectedErrMsg: "failed to parse ClickHouse database URL", | ||
}, | ||
{ | ||
url: "tcp://user:[email protected]:9000", | ||
expectedProto: protocolUnknown, | ||
expectedAddr: "", | ||
expectedErr: fmt.Errorf("invalid ClickHouse database URL"), | ||
url: "tcp://user:[email protected]:9000", | ||
expectedErrMsg: "invalid ClickHouse database URL", | ||
}, | ||
{ | ||
url: "tcp://127.0.0.1:9000/path", | ||
expectedProto: protocolUnknown, | ||
expectedAddr: "", | ||
expectedErr: fmt.Errorf("invalid ClickHouse database URL"), | ||
url: "tcp://127.0.0.1:9000/path", | ||
expectedErrMsg: "invalid ClickHouse database URL", | ||
}, | ||
{ | ||
url: "tcp://127.0.0.1:9000?key=value", | ||
expectedProto: protocolUnknown, | ||
expectedAddr: "", | ||
expectedErr: fmt.Errorf("invalid ClickHouse database URL"), | ||
url: "tcp://127.0.0.1:9000?key=value", | ||
expectedErrMsg: "invalid ClickHouse database URL", | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
proto, addr, err := parseDatabaseURL(tc.url) | ||
if tc.expectedErr != nil { | ||
assert.ErrorContains(t, err, tc.expectedErr.Error()) | ||
if tc.expectedErrMsg != "" { | ||
assert.Contains(t, err.Error(), tc.expectedErrMsg) | ||
} else { | ||
assert.Nil(t, err) | ||
require.NoError(t, err) | ||
assert.Equal(t, tc.expectedProto, proto) | ||
assert.Equal(t, tc.expectedAddr, addr) | ||
} | ||
assert.Equal(t, tc.expectedProto, proto) | ||
assert.Equal(t, tc.expectedAddr, addr) | ||
} | ||
} |