Skip to content

Commit

Permalink
refactor: Change all unit tests to use logger.NewMockCient() (#555)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
lenny-goodell authored Oct 21, 2020
1 parent 812c8b5 commit 02b6e43
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion appcontext/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion appsdk/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
6 changes: 3 additions & 3 deletions internal/bootstrap/handlers/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/security/client/vaultclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/security/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
6 changes: 3 additions & 3 deletions internal/security/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/trigger/messagebus/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/transforms/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 02b6e43

Please sign in to comment.