From 4727a8b6c7623483ab227a5bd48e35da9d202da7 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Wed, 25 Nov 2020 15:58:55 +0800 Subject: [PATCH] Format code, change tests/system to avoid breakage (#4459) autopep8 will move imports to the top of the file if they come after statements. Move the sys.path magic to another file so we can preserve import ordering. --- beater/config/config_test.go | 16 ++++++++-------- model/modeldecoder/generator/jsonschema_test.go | 3 ++- script/generate_notice.py | 13 +++++++------ tests/system/apmserver.py | 7 +------ tests/system/libbeat_paths.py | 9 +++++++++ tests/system/test_tls.py | 3 +-- .../aggregation/txmetrics/aggregator_test.go | 4 ++-- 7 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 tests/system/libbeat_paths.py diff --git a/beater/config/config_test.go b/beater/config/config_test.go index d8852b89371..a4bf7d7440e 100644 --- a/beater/config/config_test.go +++ b/beater/config/config_test.go @@ -448,24 +448,24 @@ func TestTLSSettings(t *testing.T) { "ConfiguredToRequired": { config: map[string]interface{}{"ssl": map[string]interface{}{ "client_authentication": "required", - "key": "../../testdata/tls/key.pem", - "certificate": "../../testdata/tls/certificate.pem", + "key": "../../testdata/tls/key.pem", + "certificate": "../../testdata/tls/certificate.pem", }}, tls: &tlscommon.ServerConfig{ClientAuth: 4, Certificate: testdataCertificateConfig}, }, "ConfiguredToOptional": { config: map[string]interface{}{"ssl": map[string]interface{}{ "client_authentication": "optional", - "key": "../../testdata/tls/key.pem", - "certificate": "../../testdata/tls/certificate.pem", + "key": "../../testdata/tls/key.pem", + "certificate": "../../testdata/tls/certificate.pem", }}, tls: &tlscommon.ServerConfig{ClientAuth: 3, Certificate: testdataCertificateConfig}, }, "DefaultRequiredByCA": { config: map[string]interface{}{"ssl": map[string]interface{}{ "certificate_authorities": []string{"../../testdata/tls/ca.crt.pem"}, - "key": "../../testdata/tls/key.pem", - "certificate": "../../testdata/tls/certificate.pem", + "key": "../../testdata/tls/key.pem", + "certificate": "../../testdata/tls/certificate.pem", }}, tls: &tlscommon.ServerConfig{ClientAuth: 4, Certificate: testdataCertificateConfig}, }, @@ -473,8 +473,8 @@ func TestTLSSettings(t *testing.T) { config: map[string]interface{}{"ssl": map[string]interface{}{ "client_authentication": "none", "certificate_authorities": []string{"../../testdata/tls/ca.crt.pem"}, - "key": "../../testdata/tls/key.pem", - "certificate": "../../testdata/tls/certificate.pem", + "key": "../../testdata/tls/key.pem", + "certificate": "../../testdata/tls/certificate.pem", }}, tls: &tlscommon.ServerConfig{ClientAuth: 0, Certificate: testdataCertificateConfig}, }, diff --git a/model/modeldecoder/generator/jsonschema_test.go b/model/modeldecoder/generator/jsonschema_test.go index 448c39dac0b..d35a1801c67 100644 --- a/model/modeldecoder/generator/jsonschema_test.go +++ b/model/modeldecoder/generator/jsonschema_test.go @@ -23,10 +23,11 @@ import ( "reflect" "testing" - "github.com/elastic/apm-server/model/modeldecoder/generator/generatortest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/xeipuuv/gojsonschema" + + "github.com/elastic/apm-server/model/modeldecoder/generator/generatortest" ) type testcase struct { diff --git a/script/generate_notice.py b/script/generate_notice.py index b5201f6de5e..c8248ef865d 100644 --- a/script/generate_notice.py +++ b/script/generate_notice.py @@ -19,13 +19,14 @@ # Additional third-party, non-source code dependencies, to add to the CSV output. additional_third_party_deps = [{ - "name": "Red Hat Universal Base Image minimal", - "version": "8", - "url": "https://catalog.redhat.com/software/containers/ubi8/ubi-minimal/5c359a62bed8bd75a2c3fba8", - "license": "Custom;https://www.redhat.com/licenses/EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf", - "sourceURL": "https://oss-dependencies.elastic.co/redhat/ubi/ubi-minimal-8-source.tar.gz", + "name": "Red Hat Universal Base Image minimal", + "version": "8", + "url": "https://catalog.redhat.com/software/containers/ubi8/ubi-minimal/5c359a62bed8bd75a2c3fba8", + "license": "Custom;https://www.redhat.com/licenses/EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf", + "sourceURL": "https://oss-dependencies.elastic.co/redhat/ubi/ubi-minimal-8-source.tar.gz", }] + def read_file(filename): if not os.path.isfile(filename): print("File not found {}".format(filename)) @@ -206,7 +207,7 @@ def get_url(modpath): module.get("Version", ""), module.get("Revision", ""), license["license_summary"], - "" # source URL + "" # source URL ]) for dep in additional_third_party_deps: diff --git a/tests/system/apmserver.py b/tests/system/apmserver.py index 9a02f511520..c641ed5d8cf 100644 --- a/tests/system/apmserver.py +++ b/tests/system/apmserver.py @@ -13,12 +13,7 @@ from elasticsearch import Elasticsearch, NotFoundError import requests -# Add libbeat/tests/system to the import path. -output = subprocess.check_output(["go", "list", "-m", "-f", "{{.Path}} {{.Dir}}", "all"]).decode("utf-8") -beats_line = [line for line in output.splitlines() if line.startswith("github.com/elastic/beats/")][0] -beats_dir = beats_line.split(" ", 2)[1] -sys.path.append(os.path.join(beats_dir, 'libbeat', 'tests', 'system')) - +import libbeat_paths from beat.beat import INTEGRATION_TESTS, TestCase, TimeoutError from helper import wait_until from es_helper import cleanup, default_pipelines diff --git a/tests/system/libbeat_paths.py b/tests/system/libbeat_paths.py new file mode 100644 index 00000000000..75e7c5b3aa1 --- /dev/null +++ b/tests/system/libbeat_paths.py @@ -0,0 +1,9 @@ +import os.path +import subprocess +import sys + +# Add libbeat/tests/system to the import path. +output = subprocess.check_output(["go", "list", "-m", "-f", "{{.Path}} {{.Dir}}", "all"]).decode("utf-8") +beats_line = [line for line in output.splitlines() if line.startswith("github.com/elastic/beats/")][0] +beats_dir = beats_line.split(" ", 2)[1] +sys.path.append(os.path.join(beats_dir, 'libbeat', 'tests', 'system')) diff --git a/tests/system/test_tls.py b/tests/system/test_tls.py index 5d303a8bb59..686e39458d7 100644 --- a/tests/system/test_tls.py +++ b/tests/system/test_tls.py @@ -6,13 +6,12 @@ import socket import pytest from requests.packages.urllib3.exceptions import SubjectAltNameWarning -requests.packages.urllib3.disable_warnings(SubjectAltNameWarning) - from apmserver import ServerBaseTest from apmserver import TimeoutError, integration_test INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False) +requests.packages.urllib3.disable_warnings(SubjectAltNameWarning) @integration_test class TestSecureServerBaseTest(ServerBaseTest): diff --git a/x-pack/apm-server/aggregation/txmetrics/aggregator_test.go b/x-pack/apm-server/aggregation/txmetrics/aggregator_test.go index f1221a7615c..f8ad2610166 100644 --- a/x-pack/apm-server/aggregation/txmetrics/aggregator_test.go +++ b/x-pack/apm-server/aggregation/txmetrics/aggregator_test.go @@ -77,7 +77,7 @@ func TestProcessTransformablesOverflow(t *testing.T) { MaxTransactionGroups: 2, MetricsInterval: time.Microsecond, HDRHistogramSignificantFigures: 1, - Logger: logger, + Logger: logger, }) require.NoError(t, err) @@ -214,7 +214,7 @@ func TestAggregatorRunPublishErrors(t *testing.T) { MaxTransactionGroups: 2, MetricsInterval: 10 * time.Millisecond, HDRHistogramSignificantFigures: 1, - Logger: logger, + Logger: logger, }) require.NoError(t, err)