-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpcclient: Implement fmt.Stringer for Client
This implements fmt.Stringer by returning the URL of the RPC server that the client makes requests to. Since the client config is not exported by Client, this is now the only way to return the scheme, host, and endpoint the server.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2018 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package rpcclient | ||
|
||
import "testing" | ||
|
||
func TestClientStringer(t *testing.T) { | ||
type test struct { | ||
url string | ||
host string | ||
endpoint string | ||
post bool | ||
} | ||
tests := []test{ | ||
{"https://localhost:9109", "localhost:9109", "", true}, | ||
{"wss://localhost:9109/ws", "localhost:9109", "ws", false}, | ||
} | ||
for _, test := range tests { | ||
cfg := &ConnConfig{ | ||
Host: test.host, | ||
Endpoint: test.endpoint, | ||
HTTPPostMode: test.post, | ||
DisableTLS: false, | ||
DisableConnectOnNew: true, | ||
} | ||
c, err := New(cfg, nil) | ||
if err != nil { | ||
t.Errorf("%v rpcclient.New: %v", test.url, err) | ||
continue | ||
} | ||
s := c.String() | ||
if s != test.url { | ||
t.Errorf("Expected %q, got %q", test.url, s) | ||
} | ||
} | ||
} |