From 73d5ee7581f42fbd8b3a9b8b9bbfc8a40a2d3949 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 9 Jul 2020 18:36:40 +0300 Subject: [PATCH] fix package api test and use a test logger --- api/server_test.go | 6 ++++-- api/v1/group_routes_test.go | 8 ++++++-- api/v1/metric_routes_test.go | 13 +++++++++---- api/v1/setup_teardown_routes_test.go | 7 +++++-- api/v1/status_routes_test.go | 13 +++++++++---- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/api/server_test.go b/api/server_test.go index a1c8407ba87..ef300eadcdc 100644 --- a/api/server_test.go +++ b/api/server_test.go @@ -78,9 +78,11 @@ func TestLogger(t *testing.T) { } func TestWithEngine(t *testing.T) { - execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logrus.StandardLogger()) + logger := logrus.New() + logger.SetOutput(testutils.NewTestOutput(t)) + execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logger) require.NoError(t, err) - engine, err := core.NewEngine(execScheduler, lib.Options{}, logrus.StandardLogger()) + engine, err := core.NewEngine(execScheduler, lib.Options{}, logger) require.NoError(t, err) rw := httptest.NewRecorder() diff --git a/api/v1/group_routes_test.go b/api/v1/group_routes_test.go index 94894e863a3..66701c89731 100644 --- a/api/v1/group_routes_test.go +++ b/api/v1/group_routes_test.go @@ -34,6 +34,7 @@ import ( "github.com/loadimpact/k6/core" "github.com/loadimpact/k6/core/local" "github.com/loadimpact/k6/lib" + "github.com/loadimpact/k6/lib/testutils" "github.com/loadimpact/k6/lib/testutils/minirunner" ) @@ -45,9 +46,12 @@ func TestGetGroups(t *testing.T) { g2, err := g1.Group("group 2") assert.NoError(t, err) - execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{Group: g0}, logrus.StandardLogger()) + logger := logrus.New() + logger.SetOutput(testutils.NewTestOutput(t)) + + execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{Group: g0}, logger) require.NoError(t, err) - engine, err := core.NewEngine(execScheduler, lib.Options{}, logrus.StandardLogger()) + engine, err := core.NewEngine(execScheduler, lib.Options{}, logger) require.NoError(t, err) t.Run("list", func(t *testing.T) { diff --git a/api/v1/metric_routes_test.go b/api/v1/metric_routes_test.go index 8fddda1491b..dc9acb1581b 100644 --- a/api/v1/metric_routes_test.go +++ b/api/v1/metric_routes_test.go @@ -35,14 +35,17 @@ import ( "github.com/loadimpact/k6/core" "github.com/loadimpact/k6/core/local" "github.com/loadimpact/k6/lib" + "github.com/loadimpact/k6/lib/testutils" "github.com/loadimpact/k6/lib/testutils/minirunner" "github.com/loadimpact/k6/stats" ) func TestGetMetrics(t *testing.T) { - execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logrus.StandardLogger()) + logger := logrus.New() + logger.SetOutput(testutils.NewTestOutput(t)) + execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logger) require.NoError(t, err) - engine, err := core.NewEngine(execScheduler, lib.Options{}, logrus.StandardLogger()) + engine, err := core.NewEngine(execScheduler, lib.Options{}, logger) require.NoError(t, err) engine.Metrics = map[string]*stats.Metric{ @@ -81,9 +84,11 @@ func TestGetMetrics(t *testing.T) { } func TestGetMetric(t *testing.T) { - execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logrus.StandardLogger()) + logger := logrus.New() + logger.SetOutput(testutils.NewTestOutput(t)) + execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logger) require.NoError(t, err) - engine, err := core.NewEngine(execScheduler, lib.Options{}, logrus.StandardLogger()) + engine, err := core.NewEngine(execScheduler, lib.Options{}, logger) require.NoError(t, err) engine.Metrics = map[string]*stats.Metric{ diff --git a/api/v1/setup_teardown_routes_test.go b/api/v1/setup_teardown_routes_test.go index ab7e504110d..bfeb5dd4c34 100644 --- a/api/v1/setup_teardown_routes_test.go +++ b/api/v1/setup_teardown_routes_test.go @@ -40,6 +40,7 @@ import ( "github.com/loadimpact/k6/core/local" "github.com/loadimpact/k6/js" "github.com/loadimpact/k6/lib" + "github.com/loadimpact/k6/lib/testutils" "github.com/loadimpact/k6/lib/types" "github.com/loadimpact/k6/loader" ) @@ -132,6 +133,8 @@ func TestSetupData(t *testing.T) { }, }, } + logger := logrus.New() + logger.SetOutput(testutils.NewTestOutput(t)) for _, testCase := range testCases { testCase := testCase t.Run(testCase.name, func(t *testing.T) { @@ -149,9 +152,9 @@ func TestSetupData(t *testing.T) { SetupTimeout: types.NullDurationFrom(5 * time.Second), TeardownTimeout: types.NullDurationFrom(5 * time.Second), }) - execScheduler, err := local.NewExecutionScheduler(runner, logrus.StandardLogger()) + execScheduler, err := local.NewExecutionScheduler(runner, logger) require.NoError(t, err) - engine, err := core.NewEngine(execScheduler, runner.GetOptions(), logrus.StandardLogger()) + engine, err := core.NewEngine(execScheduler, runner.GetOptions(), logger) require.NoError(t, err) globalCtx, globalCancel := context.WithCancel(context.Background()) diff --git a/api/v1/status_routes_test.go b/api/v1/status_routes_test.go index 79e1bb5478a..473f2a25371 100644 --- a/api/v1/status_routes_test.go +++ b/api/v1/status_routes_test.go @@ -38,13 +38,16 @@ import ( "github.com/loadimpact/k6/core" "github.com/loadimpact/k6/core/local" "github.com/loadimpact/k6/lib" + "github.com/loadimpact/k6/lib/testutils" "github.com/loadimpact/k6/lib/testutils/minirunner" ) func TestGetStatus(t *testing.T) { - execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logrus.StandardLogger()) + logger := logrus.New() + logger.SetOutput(testutils.NewTestOutput(t)) + execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{}, logger) require.NoError(t, err) - engine, err := core.NewEngine(execScheduler, lib.Options{}, logrus.StandardLogger()) + engine, err := core.NewEngine(execScheduler, lib.Options{}, logger) require.NoError(t, err) rw := httptest.NewRecorder() @@ -84,6 +87,8 @@ func TestPatchStatus(t *testing.T) { "too many vus": {400, Status{VUs: null.IntFrom(10), VUsMax: null.IntFrom(0)}}, "vus": {200, Status{VUs: null.IntFrom(10), VUsMax: null.IntFrom(10)}}, } + logger := logrus.New() + logger.SetOutput(testutils.NewTestOutput(t)) scenarios := lib.ScenarioConfigs{} err := json.Unmarshal([]byte(` @@ -94,9 +99,9 @@ func TestPatchStatus(t *testing.T) { for name, indata := range testdata { t.Run(name, func(t *testing.T) { - execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{Options: options}, logrus.StandardLogger()) + execScheduler, err := local.NewExecutionScheduler(&minirunner.MiniRunner{Options: options}, logger) require.NoError(t, err) - engine, err := core.NewEngine(execScheduler, options, logrus.StandardLogger()) + engine, err := core.NewEngine(execScheduler, options, logger) require.NoError(t, err) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel()