Skip to content

Commit

Permalink
chore: Add tests for runtime WithLogger opt (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd authored Mar 23, 2022
1 parent ff0e189 commit 746aa53
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
45 changes: 45 additions & 0 deletions runtime/docker/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package docker

import (
"github.com/sirupsen/logrus"
"reflect"
"testing"
)
Expand Down Expand Up @@ -72,3 +73,47 @@ func TestDocker_ClientOpt_WithHostVolumes(t *testing.T) {
}
}
}

func TestDocker_ClientOpt_WithLogger(t *testing.T) {
// setup tests
tests := []struct {
failure bool
logger *logrus.Entry
}{
{
failure: false,
logger: &logrus.Entry{},
},
{
failure: false,
logger: nil,
},
}

// run tests
for _, test := range tests {
_service, err := New(
WithLogger(test.logger),
)

if test.failure {
if err == nil {
t.Errorf("WithLogger should have returned err")
}

continue
}

if err != nil {
t.Errorf("WithLogger returned err: %v", err)
}

if test.logger == nil && _service.Logger == nil {
t.Errorf("_engine.Logger should not be nil even if nil is passed to WithLogger")
}

if test.logger != nil && !reflect.DeepEqual(_service.Logger, test.logger) {
t.Errorf("WithLogger set %v, want %v", _service.Logger, test.logger)
}
}
}
46 changes: 46 additions & 0 deletions runtime/kubernetes/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kubernetes

import (
"github.com/sirupsen/logrus"
"reflect"
"testing"
)
Expand Down Expand Up @@ -161,3 +162,48 @@ func TestKubernetes_ClientOpt_WithPrivilegedImages(t *testing.T) {
}
}
}

func TestKubernetes_ClientOpt_WithLogger(t *testing.T) {
// setup tests
tests := []struct {
failure bool
logger *logrus.Entry
}{
{
failure: false,
logger: &logrus.Entry{},
},
{
failure: false,
logger: nil,
},
}

// run tests
for _, test := range tests {
_engine, err := New(
WithConfigFile("testdata/config"),
WithLogger(test.logger),
)

if test.failure {
if err == nil {
t.Errorf("WithLogger should have returned err")
}

continue
}

if err != nil {
t.Errorf("WithLogger returned err: %v", err)
}

if test.logger == nil && _engine.Logger == nil {
t.Errorf("_engine.Logger should not be nil even if nil is passed to WithLogger")
}

if test.logger != nil && !reflect.DeepEqual(_engine.Logger, test.logger) {
t.Errorf("WithLogger set %v, want %v", _engine.Logger, test.logger)
}
}
}

0 comments on commit 746aa53

Please sign in to comment.