Skip to content

Commit

Permalink
fix: return error from instance version (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
enocom authored Jan 18, 2022
1 parent e138611 commit d9fc819
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions proxy/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func NewConnSrc(instance string, l net.Listener) <-chan Conn {
return ch
}

// InstanceVersionContext uses client cache to return instance version string.
// InstanceVersion uses client cache to return instance version string.
//
// Deprecated: Use Client.InstanceVersionContext instead.
func (c *Client) InstanceVersion(instance string) (string, error) {
Expand All @@ -586,7 +586,7 @@ func (c *Client) InstanceVersion(instance string) (string, error) {
func (c *Client) InstanceVersionContext(ctx context.Context, instance string) (string, error) {
_, _, version, err := c.cachedCfg(ctx, instance)
if err != nil {
return "", nil
return "", err
}
return version, nil
}
Expand Down
44 changes: 44 additions & 0 deletions proxy/proxy/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,47 @@ func TestConnectingWithInvalidConfig(t *testing.T) {
t.Fatalf("wanted ErrUnexpectedFailure, got = %v", err)
}
}

var (
errLocal = errors.New("local failed")
errRemote = errors.New("remote failed")
)

type failingCertSource struct{}

func (cs failingCertSource) Local(instance string) (tls.Certificate, error) {
return tls.Certificate{}, errLocal
}

func (cs failingCertSource) Remote(instance string) (cert *x509.Certificate, addr, name, version string, err error) {
return nil, "", "", "", errRemote
}

func TestInstanceVersionContext(t *testing.T) {
testCases := []struct {
certSource CertSource
wantErr error
wantVersion string
}{
{
certSource: newCertSource(&fakeCerts{}, forever),
wantErr: nil,
wantVersion: "fake version",
},
{
certSource: failingCertSource{},
wantErr: errLocal,
wantVersion: "",
},
}
for _, tc := range testCases {
c := newClient(tc.certSource)
v, err := c.InstanceVersionContext(context.Background(), instance)
if v != tc.wantVersion {
t.Fatalf("want version = %v, got version = %v", tc.wantVersion, v)
}
if err != tc.wantErr {
t.Fatalf("want = %v, got = %v", tc.wantErr, err)
}
}
}

0 comments on commit d9fc819

Please sign in to comment.