-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix etcdv3 client won't return error when no endpoint is available
- Loading branch information
Showing
3 changed files
with
96 additions
and
2 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,80 @@ | ||
package etcdv3 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
) | ||
|
||
const ( | ||
// IrRelevantEndpoint is an address which does not exists. | ||
IrRelevantEndpoint = "http://irrelevant:12345" | ||
) | ||
|
||
func TestNewClient(t *testing.T) { | ||
client, err := NewClient( | ||
context.Background(), | ||
[]string{IrRelevantEndpoint}, | ||
ClientOptions{ | ||
DialTimeout: 3 * time.Second, | ||
DialKeepAlive: 3 * time.Second, | ||
}, | ||
) | ||
if err != nil { | ||
t.Fatalf("unexpected error creating client: %v", err) | ||
} | ||
if client == nil { | ||
t.Fatal("expected new Client, got nil") | ||
} | ||
} | ||
|
||
func TestClientOptions(t *testing.T) { | ||
client, err := NewClient( | ||
context.Background(), | ||
[]string{}, | ||
ClientOptions{ | ||
Cert: "", | ||
Key: "", | ||
CACert: "", | ||
DialTimeout: 3 * time.Second, | ||
DialKeepAlive: 3 * time.Second, | ||
}, | ||
) | ||
if err == nil { | ||
t.Errorf("expected error: %v", err) | ||
} | ||
if client != nil { | ||
t.Fatalf("expected client to be nil on failure") | ||
} | ||
|
||
_, err = NewClient( | ||
context.Background(), | ||
[]string{IrRelevantEndpoint}, | ||
ClientOptions{ | ||
Cert: "does-not-exist.crt", | ||
Key: "does-not-exist.key", | ||
CACert: "does-not-exist.CACert", | ||
DialTimeout: 3 * time.Second, | ||
DialKeepAlive: 3 * time.Second, | ||
}, | ||
) | ||
if err == nil { | ||
t.Errorf("expected error: %v", err) | ||
} | ||
|
||
client, err = NewClient( | ||
context.Background(), | ||
[]string{IrRelevantEndpoint}, | ||
ClientOptions{ | ||
DialOptions: []grpc.DialOption{grpc.WithBlock()}, | ||
}, | ||
) | ||
if err == nil { | ||
t.Errorf("expected connection should fail") | ||
} | ||
if client != nil { | ||
t.Errorf("expected client to be nil on failure") | ||
} | ||
} |
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