This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convenience method for creating new cluster from string slice
Creating a client against a cluster is a bit verbose without this.
- Loading branch information
Matt Jaffee
committed
Jun 30, 2017
1 parent
0a28916
commit c76e1e2
Showing
2 changed files
with
55 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 @@ | ||
package pilosa | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewClientFromAddresses(t *testing.T) { | ||
cli, err := NewClientFromAddresses([]string{":10101", "node0.pilosa.com:10101", "node2.pilosa.com"}, &ClientOptions{}) | ||
|
||
if err != nil { | ||
t.Fatalf("Creating client from addresses: %v", err) | ||
} | ||
expectedHosts := []URI{ | ||
{scheme: "http", port: 10101, host: "localhost"}, | ||
{scheme: "http", port: 10101, host: "node0.pilosa.com"}, | ||
{scheme: "http", port: 10101, host: "node2.pilosa.com"}, | ||
} | ||
actualHosts := cli.cluster.Hosts() | ||
if !reflect.DeepEqual(actualHosts, expectedHosts) { | ||
t.Fatalf("Unexpected hosts in client's cluster, got: %v, expected: %v", actualHosts, expectedHosts) | ||
} | ||
|
||
cli, err = NewClientFromAddresses([]string{"://"}, &ClientOptions{}) | ||
if err == nil { | ||
t.Fatalf("Did not get expected error when creating client: %v", cli.cluster.Hosts()) | ||
} | ||
|
||
cli, err = NewClientFromAddresses([]string{}, &ClientOptions{}) | ||
if err != nil { | ||
t.Fatalf("Got error when creating empty client from addresses: %v", err) | ||
} | ||
|
||
cli, err = NewClientFromAddresses(nil, &ClientOptions{}) | ||
if err != nil { | ||
t.Fatalf("Got error when creating empty client from addresses: %v", err) | ||
} | ||
} |