Skip to content

Commit

Permalink
fix package api test and use a test logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Jul 20, 2020
1 parent bd5f9b5 commit 73d5ee7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
6 changes: 4 additions & 2 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions api/v1/group_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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) {
Expand Down
13 changes: 9 additions & 4 deletions api/v1/metric_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
7 changes: 5 additions & 2 deletions api/v1/setup_teardown_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand All @@ -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())
Expand Down
13 changes: 9 additions & 4 deletions api/v1/status_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(`
Expand All @@ -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()
Expand Down

0 comments on commit 73d5ee7

Please sign in to comment.