From 02b6e43ef5ccbf3dbddfffb58acaab4da430d1ee Mon Sep 17 00:00:00 2001 From: Lenny Goodell <44779287+lenny-intel@users.noreply.github.com> Date: Tue, 20 Oct 2020 17:10:13 -0700 Subject: [PATCH] refactor: Change all unit tests to use logger.NewMockCient() (#555) This is so test.log files are no longer created and the test results are not cluttered with log messages. closes #477 Signed-off-by: lenny --- appcontext/context_test.go | 2 +- appsdk/sdk_test.go | 2 +- internal/bootstrap/handlers/version_test.go | 6 +++--- internal/runtime/runtime_test.go | 2 +- internal/security/client/vaultclient_test.go | 2 +- internal/security/credentials_test.go | 2 +- internal/security/secret_test.go | 6 +++--- internal/trigger/messagebus/messaging_test.go | 2 +- internal/webserver/server_test.go | 2 +- pkg/transforms/tags_test.go | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/appcontext/context_test.go b/appcontext/context_test.go index 82950cfca..8ef526747 100644 --- a/appcontext/context_test.go +++ b/appcontext/context_test.go @@ -42,7 +42,7 @@ var lc logger.LoggingClient func init() { eventClient = coredata.NewEventClient(localURL.New("http://test" + clients.ApiEventRoute)) - lc = logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + lc = logger.NewMockClient() } func TestMarkAsPushedNoClient(t *testing.T) { ctx := Context{ diff --git a/appsdk/sdk_test.go b/appsdk/sdk_test.go index 4ae4db4a6..0f7c655cd 100644 --- a/appsdk/sdk_test.go +++ b/appsdk/sdk_test.go @@ -41,7 +41,7 @@ var lc logger.LoggingClient func TestMain(m *testing.M) { // No remote and no file results in STDOUT logging only - lc = logger.NewClient("app_functions_sdk_go", false, "", "DEBUG") + lc = logger.NewMockClient() m.Run() } diff --git a/internal/bootstrap/handlers/version_test.go b/internal/bootstrap/handlers/version_test.go index 6744d1bf5..48ead7f7f 100644 --- a/internal/bootstrap/handlers/version_test.go +++ b/internal/bootstrap/handlers/version_test.go @@ -26,10 +26,10 @@ import ( "testing" bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/container" - "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/logging" "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/startup" "github.com/edgexfoundry/go-mod-bootstrap/config" "github.com/edgexfoundry/go-mod-bootstrap/di" + "github.com/edgexfoundry/go-mod-core-contracts/clients/logger" "github.com/edgexfoundry/go-mod-registry/registry" "github.com/stretchr/testify/assert" @@ -54,12 +54,12 @@ func TestValidateVersionMatch(t *testing.T) { Clients: clients, } - logger := logging.FactoryToStdout("clients-test") + lc := logger.NewMockClient() var registryClient registry.Client = nil dic := di.NewContainer(di.ServiceConstructorMap{ bootstrapContainer.LoggingClientInterfaceName: func(get di.Get) interface{} { - return logger + return lc }, bootstrapContainer.RegistryClientInterfaceName: func(get di.Get) interface{} { return registryClient diff --git a/internal/runtime/runtime_test.go b/internal/runtime/runtime_test.go index fc84adf67..437cf6504 100644 --- a/internal/runtime/runtime_test.go +++ b/internal/runtime/runtime_test.go @@ -43,7 +43,7 @@ const ( ) func init() { - lc = logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + lc = logger.NewMockClient() } func TestProcessMessageNoTransforms(t *testing.T) { diff --git a/internal/security/client/vaultclient_test.go b/internal/security/client/vaultclient_test.go index 36efc88ae..b70cbb76e 100644 --- a/internal/security/client/vaultclient_test.go +++ b/internal/security/client/vaultclient_test.go @@ -52,7 +52,7 @@ func TestGetVaultClient(t *testing.T) { portNum, _ := strconv.Atoi(port) bkgCtx := context.Background() - lc := logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + lc := logger.NewMockClient() testSecretStoreInfo := config.SecretStoreInfo{ Host: host, diff --git a/internal/security/credentials_test.go b/internal/security/credentials_test.go index eefe6d0f5..0e14ab666 100644 --- a/internal/security/credentials_test.go +++ b/internal/security/credentials_test.go @@ -231,7 +231,7 @@ func tearDownGetInsecureSecrets(t *testing.T, origEnv string) { } func newMockSecretProvider(configuration *common.ConfigurationStruct) *SecretProviderImpl { - logClient := logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + logClient := logger.NewMockClient() mockSP := NewSecretProvider(logClient, configuration) mockSP.SharedSecretClient = &mockSecretClient{} mockSP.ExclusiveSecretClient = &mockSecretClient{} diff --git a/internal/security/secret_test.go b/internal/security/secret_test.go index f552f24c5..790e86033 100644 --- a/internal/security/secret_test.go +++ b/internal/security/secret_test.go @@ -41,7 +41,7 @@ import ( func TestNewSecretProvider(t *testing.T) { config := &common.ConfigurationStruct{} - lc := logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + lc := logger.NewMockClient() secretProvider := NewSecretProvider(lc, config) assert.NotNil(t, secretProvider, "secretProvider from NewSecretProvider should not be nil") @@ -64,7 +64,7 @@ func TestInitializeClientFromSecretProvider(t *testing.T) { ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() - lc := logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + lc := logger.NewMockClient() testSecretStoreInfo := config.SecretStoreInfo{ Host: host, @@ -230,7 +230,7 @@ func TestConfigAdditonalRetryAttempts(t *testing.T) { defer cancelFunc() - lc := logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + lc := logger.NewMockClient() origEnv := os.Getenv(EnvSecretStore) diff --git a/internal/trigger/messagebus/messaging_test.go b/internal/trigger/messagebus/messaging_test.go index 7f91993f8..39344cc65 100644 --- a/internal/trigger/messagebus/messaging_test.go +++ b/internal/trigger/messagebus/messaging_test.go @@ -39,7 +39,7 @@ import ( var logClient logger.LoggingClient func init() { - logClient = logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + logClient = logger.NewMockClient() } func TestInitialize(t *testing.T) { diff --git a/internal/webserver/server_test.go b/internal/webserver/server_test.go index 998094635..763660a4f 100644 --- a/internal/webserver/server_test.go +++ b/internal/webserver/server_test.go @@ -39,7 +39,7 @@ var logClient logger.LoggingClient var config *common.ConfigurationStruct func TestMain(m *testing.M) { - logClient = logger.NewClient("app_functions_sdk_go", false, "./test.log", "DEBUG") + logClient = logger.NewMockClient() config = &common.ConfigurationStruct{} m.Run() } diff --git a/pkg/transforms/tags_test.go b/pkg/transforms/tags_test.go index be93c2208..4aa7388d6 100644 --- a/pkg/transforms/tags_test.go +++ b/pkg/transforms/tags_test.go @@ -51,7 +51,7 @@ var allTagsAdded = map[string]string{ func TestTags_AddTags(t *testing.T) { appContext := appcontext.Context{ - LoggingClient: logger.NewClientStdOut("Unit Test", false, "DEBUG"), + LoggingClient: logger.NewMockClient(), } tests := []struct {