diff --git a/internal/services/generalFunctions_test.go b/internal/services/generalFunctions_test.go index 7f37bcc..96efb9a 100644 --- a/internal/services/generalFunctions_test.go +++ b/internal/services/generalFunctions_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/fonteeBoa/go-log-guardian/internal/services" + "github.com/fonteeBoa/go-log-guardian/internal/testUtils/mocks" "github.com/fonteeBoa/go-log-guardian/pkg/domain" ) @@ -40,8 +41,8 @@ func TestDebugPrintsMessageForLogDebugPriority(t *testing.T) { }() priority := domain.LOG_DEBUG - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError services.Debug(priority, genericErrMsg, errMsg) @@ -67,8 +68,8 @@ func TestDebugDoesNotPrintMessageForNonLogDebugPriority(t *testing.T) { }() priority := domain.LOG_INFO - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError services.Debug(priority, genericErrMsg, errMsg) diff --git a/internal/services/logFunctions_test.go b/internal/services/logFunctions_test.go index eb6f5fe..df2f4d8 100644 --- a/internal/services/logFunctions_test.go +++ b/internal/services/logFunctions_test.go @@ -6,14 +6,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/fonteeBoa/go-log-guardian/internal/services" + "github.com/fonteeBoa/go-log-guardian/internal/testUtils/mocks" "github.com/fonteeBoa/go-log-guardian/pkg/domain" ) func TestFunction(t *testing.T) { priority := domain.LOG_INFO functionName := "TestFunction" - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError logFunction := services.Function(priority, functionName, genericErrMsg, errMsg) @@ -27,10 +28,10 @@ func TestFunction(t *testing.T) { func TestDatabase(t *testing.T) { priority := domain.LOG_DEBUG - tableName := "TestTable" + tableName := mocks.MockTable query := "SELECT * FROM TestTable" - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError databaseLog := services.Database(priority, tableName, query, genericErrMsg, errMsg) @@ -49,8 +50,8 @@ func TestRequest(t *testing.T) { statusCode := 500 path := "/test/path" responseSize := 1024 - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError requestLog := services.Request(priority, method, statusCode, path, responseSize, genericErrMsg, errMsg) @@ -67,8 +68,8 @@ func TestRequest(t *testing.T) { func TestDetails(t *testing.T) { priority := domain.LOG_CRIT - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError logDetails := services.Details(priority, genericErrMsg, errMsg) diff --git a/internal/services/newlogs_test.go b/internal/services/newlogs_test.go index c337d27..747c61b 100644 --- a/internal/services/newlogs_test.go +++ b/internal/services/newlogs_test.go @@ -6,13 +6,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/fonteeBoa/go-log-guardian/internal/services" + "github.com/fonteeBoa/go-log-guardian/internal/testUtils/mocks" + "github.com/fonteeBoa/go-log-guardian/pkg/domain" ) func TestNewLogDetails(t *testing.T) { priority := domain.LOG_INFO - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError logDetails := services.NewLogDetails(priority, genericErrMsg, errMsg) @@ -26,8 +28,8 @@ func TestNewLogDetails(t *testing.T) { func TestNewFunctionLog(t *testing.T) { priority := domain.LOG_DEBUG functionName := "TestFunction" - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError functionLog := services.NewFunctionLog(priority, functionName, genericErrMsg, errMsg) @@ -41,10 +43,10 @@ func TestNewFunctionLog(t *testing.T) { func TestNewDatabaseLog(t *testing.T) { priority := domain.LOG_NOTICE - tableName := "TestTable" + tableName := mocks.MockTable query := "SELECT * FROM TestTable" - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError databaseLog := services.NewDatabaseLog(priority, tableName, query, genericErrMsg, errMsg) @@ -63,8 +65,8 @@ func TestNewRequestLog(t *testing.T) { statusCode := 500 path := "/test/path" responseSize := 1024 - genericErrMsg := "Test generic error" - errMsg := "Test specific error" + genericErrMsg := mocks.MockGeneralError + errMsg := mocks.MockSpecificError requestLog := services.NewRequestLog(priority, method, statusCode, path, responseSize, genericErrMsg, errMsg) diff --git a/internal/testUtils/mocks/mocksGerais.go b/internal/testUtils/mocks/mocksGerais.go new file mode 100644 index 0000000..42c24ab --- /dev/null +++ b/internal/testUtils/mocks/mocksGerais.go @@ -0,0 +1,8 @@ +package mocks + +const ( + MockError = "error" + MockGeneralError = "general.error" + MockTable = "TestTable" + MockSpecificError = "Test specific error" +) diff --git a/pkg/logs_test.go b/pkg/logs_test.go index d82fef2..8c0dff5 100644 --- a/pkg/logs_test.go +++ b/pkg/logs_test.go @@ -3,6 +3,7 @@ package pkg_test import ( "testing" + "github.com/fonteeBoa/go-log-guardian/internal/testUtils/mocks" "github.com/fonteeBoa/go-log-guardian/pkg" "github.com/fonteeBoa/go-log-guardian/pkg/domain" ) @@ -12,13 +13,13 @@ func TestLogFunction(t *testing.T) { LogDetails: domain.LogDetails{ Priority: domain.LOG_ERR, LogLevel: "debug", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, }, FunctionName: "testFunction", } - success, result := pkg.LogFunction(domain.LOG_ERR, "testFunction", "generic error", "specific error") + success, result := pkg.LogFunction(domain.LOG_ERR, "testFunction", mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogFunction failed to save log") @@ -39,14 +40,14 @@ func TestLogDataBase(t *testing.T) { LogDetails: domain.LogDetails{ Priority: domain.LOG_ERR, LogLevel: "debug", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, }, - TableName: "testTable", + TableName: mocks.MockTable, Query: "testQuery", } - success, result := pkg.LogDataBase(domain.LOG_ERR, "testTable", "testQuery", "generic error", "specific error") + success, result := pkg.LogDataBase(domain.LOG_ERR, mocks.MockTable, "testQuery", mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogDataBase failed to save log") @@ -68,8 +69,8 @@ func TestLogRequests(t *testing.T) { LogDetails: domain.LogDetails{ Priority: domain.LOG_ERR, LogLevel: "debug", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, }, Method: "GET", StatusCode: 200, @@ -77,7 +78,7 @@ func TestLogRequests(t *testing.T) { ResponseSize: 100, } - success, result := pkg.LogRequests(domain.LOG_ERR, "GET", 200, "/test", 100, "generic error", "specific error") + success, result := pkg.LogRequests(domain.LOG_ERR, "GET", 200, "/test", 100, mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogRequests failed to save log") @@ -99,11 +100,11 @@ func TestLog(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_DEBUG, LogLevel: "debug", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.Log(domain.LOG_DEBUG, "generic error", "specific error") + success, result := pkg.Log(domain.LOG_DEBUG, mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("Log failed to save log") @@ -121,11 +122,11 @@ func TestLogEmerg(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_EMERG, LogLevel: "LOG_EMERG", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.LogEmerg("generic error", "specific error") + success, result := pkg.LogEmerg(mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogEmerg failed to save log") @@ -143,11 +144,11 @@ func TestLogCritical(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_CRIT, LogLevel: "LOG_CRIT", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.LogCritical("generic error", "specific error") + success, result := pkg.LogCritical(mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogCritical failed to save log") @@ -165,11 +166,11 @@ func TestLogError(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_ERR, LogLevel: "LOG_ERR", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.LogError(domain.LOG_ERR, "generic error", "specific error") + success, result := pkg.LogError(domain.LOG_ERR, mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogError failed to save log") @@ -187,11 +188,11 @@ func TestLogAlert(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_ALERT, LogLevel: "LOG_ALERT", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.LogAlert("generic error", "specific error") + success, result := pkg.LogAlert(mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogAlert failed to save log") @@ -209,11 +210,11 @@ func TestLogWarning(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_WARNING, LogLevel: "LOG_WARNING", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.LogWarning("generic error", "specific error") + success, result := pkg.LogWarning(mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogWarning failed to save log") @@ -231,11 +232,11 @@ func TestLogNotice(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_NOTICE, LogLevel: "LOG_NOTICE", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.LogNotice("generic error", "specific error") + success, result := pkg.LogNotice(mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogNotice failed to save log") @@ -253,11 +254,11 @@ func TestLogInfo(t *testing.T) { expectedLog := domain.LogDetails{ Priority: domain.LOG_INFO, LogLevel: "LOG_INFO", - GenericErrorMessage: "generic error", - ErrorMessage: "specific error", + GenericErrorMessage: mocks.MockGeneralError, + ErrorMessage: mocks.MockSpecificError, } - success, result := pkg.LogInfo("generic error", "specific error") + success, result := pkg.LogInfo(mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogInfo failed to save log") @@ -272,7 +273,7 @@ func TestLogInfo(t *testing.T) { // Teste para a função LogDebug func TestLogDebug(t *testing.T) { - success := pkg.LogDebug("generic error", "specific error") + success := pkg.LogDebug(mocks.MockGeneralError, mocks.MockSpecificError) if !success { t.Errorf("LogDebug failed")