Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add tests for runtime WithLogger opt #295

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}