From 31554396b7085ba18b90ffd409abd29aad7b5724 Mon Sep 17 00:00:00 2001 From: eapolinario Date: Fri, 11 Sep 2020 14:08:47 -0700 Subject: [PATCH] remove individual Locality properties. Signed-off-by: eapolinario --- internal/app/transport/request.go | 4 +--- internal/app/transport/request_test.go | 16 ++-------------- internal/app/transport/requestv2.go | 15 --------------- internal/app/transport/requestv3.go | 15 --------------- 4 files changed, 3 insertions(+), 47 deletions(-) diff --git a/internal/app/transport/request.go b/internal/app/transport/request.go index d7dc52f9..a1448f09 100644 --- a/internal/app/transport/request.go +++ b/internal/app/transport/request.go @@ -13,6 +13,7 @@ type RequestVersion struct { V3 *discoveryv3.DiscoveryRequest } +// Locality is an interface to abstract the differences between the v2 and v3 Locality type type Locality struct { Region string Zone string @@ -28,9 +29,6 @@ type Request interface { GetNodeMetadata() *structpb.Struct GetCluster() string GetError() *status.Status - GetRegion() string - GetZone() string - GetSubZone() string GetLocality() *Locality GetResponseNonce() string GetRaw() *RequestVersion diff --git a/internal/app/transport/request_test.go b/internal/app/transport/request_test.go index ef92f703..69c5336c 100644 --- a/internal/app/transport/request_test.go +++ b/internal/app/transport/request_test.go @@ -103,22 +103,10 @@ func TestGetError(t *testing.T) { assert.Equal(t, requestv2.GetError(), requestv3.GetError()) } -func TestGetRegion(t *testing.T) { +func TestGetLocality(t *testing.T) { requestv2 := NewRequestV2(&requestV2) requestv3 := NewRequestV3(&requestV3) - assert.Equal(t, requestv2.GetRegion(), requestv3.GetRegion()) -} - -func TestGetZone(t *testing.T) { - requestv2 := NewRequestV2(&requestV2) - requestv3 := NewRequestV3(&requestV3) - assert.Equal(t, requestv2.GetZone(), requestv3.GetZone()) -} - -func TestGetSubZone(t *testing.T) { - requestv2 := NewRequestV2(&requestV2) - requestv3 := NewRequestV3(&requestV3) - assert.Equal(t, requestv2.GetSubZone(), requestv3.GetSubZone()) + assert.Equal(t, requestv2.GetLocality(), requestv3.GetLocality()) } func TestGetResponseNonce(t *testing.T) { diff --git a/internal/app/transport/requestv2.go b/internal/app/transport/requestv2.go index 18ae4b04..1c0c730e 100644 --- a/internal/app/transport/requestv2.go +++ b/internal/app/transport/requestv2.go @@ -58,21 +58,6 @@ func (r *RequestV2) GetTypeURL() string { return r.r.GetTypeUrl() } -// GetRegion gets the error details -func (r *RequestV2) GetRegion() string { - return r.r.GetNode().GetLocality().GetRegion() -} - -// GetZone gets the error details -func (r *RequestV2) GetZone() string { - return r.r.GetNode().GetLocality().GetZone() -} - -// GetSubZone gets the error details -func (r *RequestV2) GetSubZone() string { - return r.r.GetNode().GetLocality().GetSubZone() -} - // GetLocality gets the node locality func (r *RequestV2) GetLocality() *Locality { locality := r.r.GetNode().GetLocality() diff --git a/internal/app/transport/requestv3.go b/internal/app/transport/requestv3.go index b63fdfe4..c4044c66 100644 --- a/internal/app/transport/requestv3.go +++ b/internal/app/transport/requestv3.go @@ -58,21 +58,6 @@ func (r *RequestV3) GetTypeURL() string { return r.r.GetTypeUrl() } -// GetRegion gets the error details -func (r *RequestV3) GetRegion() string { - return r.r.GetNode().GetLocality().GetRegion() -} - -// GetZone gets the error details -func (r *RequestV3) GetZone() string { - return r.r.GetNode().GetLocality().GetZone() -} - -// GetSubZone gets the error details -func (r *RequestV3) GetSubZone() string { - return r.r.GetNode().GetLocality().GetSubZone() -} - // GetLocality gets the node locality func (r *RequestV3) GetLocality() *Locality { locality := r.r.GetNode().GetLocality()