From 4ef8c7c1d8e4b41bad2bd3a6760186786a180a77 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 25 Oct 2021 09:20:05 +0200 Subject: [PATCH] discovery/xds: make each test use separate HTTP resource config So tests can run in parallel without races. Signed-off-by: Mateusz Gozdek --- discovery/xds/client_test.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/discovery/xds/client_test.go b/discovery/xds/client_test.go index fda7ba320..ff5217359 100644 --- a/discovery/xds/client_test.go +++ b/discovery/xds/client_test.go @@ -26,15 +26,17 @@ import ( "google.golang.org/protobuf/types/known/anypb" ) -var httpResourceConf = &HTTPResourceClientConfig{ - HTTPClientConfig: config.HTTPClientConfig{ - TLSConfig: config.TLSConfig{InsecureSkipVerify: true}, - }, - ResourceType: "monitoring", - // Some known type. - ResourceTypeURL: "type.googleapis.com/envoy.service.discovery.v3.DiscoveryRequest", - Server: "http://localhost", - ClientID: "test-id", +func testHTTPResourceConfig() *HTTPResourceClientConfig { + return &HTTPResourceClientConfig{ + HTTPClientConfig: config.HTTPClientConfig{ + TLSConfig: config.TLSConfig{InsecureSkipVerify: true}, + }, + ResourceType: "monitoring", + // Some known type. + ResourceTypeURL: "type.googleapis.com/envoy.service.discovery.v3.DiscoveryRequest", + Server: "http://localhost", + ClientID: "test-id", + } } func urlMustParse(str string) *url.URL { @@ -106,7 +108,7 @@ func createTestHTTPResourceClient(t *testing.T, conf *HTTPResourceClientConfig, } func TestHTTPResourceClientFetchEmptyResponse(t *testing.T) { - client, cleanup := createTestHTTPResourceClient(t, httpResourceConf, ProtocolV3, func(request *v3.DiscoveryRequest) (*v3.DiscoveryResponse, error) { + client, cleanup := createTestHTTPResourceClient(t, testHTTPResourceConfig(), ProtocolV3, func(request *v3.DiscoveryRequest) (*v3.DiscoveryResponse, error) { return nil, nil }) defer cleanup() @@ -117,7 +119,7 @@ func TestHTTPResourceClientFetchEmptyResponse(t *testing.T) { } func TestHTTPResourceClientFetchFullResponse(t *testing.T) { - client, cleanup := createTestHTTPResourceClient(t, httpResourceConf, ProtocolV3, func(request *v3.DiscoveryRequest) (*v3.DiscoveryResponse, error) { + client, cleanup := createTestHTTPResourceClient(t, testHTTPResourceConfig(), ProtocolV3, func(request *v3.DiscoveryRequest) (*v3.DiscoveryResponse, error) { if request.VersionInfo == "1" { return nil, nil } @@ -146,7 +148,7 @@ func TestHTTPResourceClientFetchFullResponse(t *testing.T) { } func TestHTTPResourceClientServerError(t *testing.T) { - client, cleanup := createTestHTTPResourceClient(t, httpResourceConf, ProtocolV3, func(request *v3.DiscoveryRequest) (*v3.DiscoveryResponse, error) { + client, cleanup := createTestHTTPResourceClient(t, testHTTPResourceConfig(), ProtocolV3, func(request *v3.DiscoveryRequest) (*v3.DiscoveryResponse, error) { return nil, errors.New("server error") }) defer cleanup()