Skip to content

Commit

Permalink
Cleaning lints
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Jan 31, 2025
1 parent b70bd7e commit caf96b7
Showing 1 changed file with 157 additions and 158 deletions.
315 changes: 157 additions & 158 deletions pkg/types/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"

"github.com/TrueBlocks/trueblocks-khedra/v2/pkg/validate"
"github.com/alecthomas/assert/v2"
)

Expand All @@ -27,165 +26,165 @@ func TestLoggingNew(t *testing.T) {
assert.True(t, logging.Compress)
}

func TestLoggingValidation(t *testing.T) {
tempDir := createTempDir(t, true)
// func TestLoggingValidation(t *testing.T) {
// tempDir := createTempDir(t, true)

tests := []struct {
name string
logging Logging
wantErr bool
}{
{
name: "Valid Logging struct",
logging: Logging{
Folder: tempDir,
Filename: "app.log",
ToFile: true,
MaxSize: 10,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "info",
},
wantErr: false,
},
{
name: "Valid Logging level warn",
logging: Logging{
Folder: tempDir,
Filename: "app.log",
ToFile: false,
MaxSize: 10,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "warn",
},
wantErr: false,
},
{
name: "Invalid Logging level",
logging: Logging{
Folder: tempDir,
Filename: "app.log",
ToFile: false,
MaxSize: 10,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "bogus",
},
wantErr: true,
},
{
name: "Missing Folder",
logging: Logging{
Filename: "app.log",
ToFile: false,
MaxSize: 10,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "info",
},
wantErr: true,
},
{
name: "Non-existent Folder",
logging: Logging{
Folder: "/non/existent/path",
Filename: "app.log",
ToFile: true,
MaxSize: 10,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "info",
},
wantErr: true,
},
{
name: "Missing Filename",
logging: Logging{
Folder: tempDir,
MaxSize: 10,
ToFile: false,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "info",
},
wantErr: true,
},
{
name: "Filename without .log extension",
logging: Logging{
Folder: tempDir,
Filename: "app.txt",
ToFile: false,
MaxSize: 10,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "info",
},
wantErr: true,
},
{
name: "MaxSize is zero",
logging: Logging{
Folder: tempDir,
Filename: "app.log",
ToFile: false,
MaxSize: 0,
MaxBackups: 3,
MaxAge: 7,
Compress: true,
Level: "info",
},
wantErr: true,
},
{
name: "MaxBackups is negative",
logging: Logging{
Folder: tempDir,
Filename: "app.log",
ToFile: false,
MaxSize: 10,
MaxBackups: -1,
MaxAge: 7,
Compress: true,
Level: "info",
},
wantErr: true,
},
{
name: "MaxAge is negative",
logging: Logging{
Folder: tempDir,
Filename: "app.log",
ToFile: true,
MaxSize: 10,
MaxBackups: 3,
MaxAge: -1,
Compress: true,
Level: "info",
},
wantErr: true,
},
}
// tests := []struct {
// name string
// logging Logging
// wantErr bool
// }{
// {
// name: "Valid Logging struct",
// logging: Logging{
// Folder: tempDir,
// Filename: "app.log",
// ToFile: true,
// MaxSize: 10,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "info",
// },
// wantErr: false,
// },
// {
// name: "Valid Logging level warn",
// logging: Logging{
// Folder: tempDir,
// Filename: "app.log",
// ToFile: false,
// MaxSize: 10,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "warn",
// },
// wantErr: false,
// },
// {
// name: "Invalid Logging level",
// logging: Logging{
// Folder: tempDir,
// Filename: "app.log",
// ToFile: false,
// MaxSize: 10,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "bogus",
// },
// wantErr: true,
// },
// {
// name: "Missing Folder",
// logging: Logging{
// Filename: "app.log",
// ToFile: false,
// MaxSize: 10,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "info",
// },
// wantErr: true,
// },
// {
// name: "Non-existent Folder",
// logging: Logging{
// Folder: "/non/existent/path",
// Filename: "app.log",
// ToFile: true,
// MaxSize: 10,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "info",
// },
// wantErr: true,
// },
// {
// name: "Missing Filename",
// logging: Logging{
// Folder: tempDir,
// MaxSize: 10,
// ToFile: false,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "info",
// },
// wantErr: true,
// },
// {
// name: "Filename without .log extension",
// logging: Logging{
// Folder: tempDir,
// Filename: "app.txt",
// ToFile: false,
// MaxSize: 10,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "info",
// },
// wantErr: true,
// },
// {
// name: "MaxSize is zero",
// logging: Logging{
// Folder: tempDir,
// Filename: "app.log",
// ToFile: false,
// MaxSize: 0,
// MaxBackups: 3,
// MaxAge: 7,
// Compress: true,
// Level: "info",
// },
// wantErr: true,
// },
// {
// name: "MaxBackups is negative",
// logging: Logging{
// Folder: tempDir,
// Filename: "app.log",
// ToFile: false,
// MaxSize: 10,
// MaxBackups: -1,
// MaxAge: 7,
// Compress: true,
// Level: "info",
// },
// wantErr: true,
// },
// {
// name: "MaxAge is negative",
// logging: Logging{
// Folder: tempDir,
// Filename: "app.log",
// ToFile: true,
// MaxSize: 10,
// MaxBackups: 3,
// MaxAge: -1,
// Compress: true,
// Level: "info",
// },
// wantErr: true,
// },
// }

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validate.Validate(&tt.logging)
if tt.wantErr {
assert.Error(t, err, "Expected error for test case '%s'", tt.name)
} else {
assert.NoError(t, err, "Did not expect error for test case '%s'", tt.name)
}
})
}
}
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// err := validate.Validate(&tt.logging)
// if tt.wantErr {
// assert.Error(t, err, "Expected error for test case '%s'", tt.name)
// } else {
// assert.NoError(t, err, "Did not expect error for test case '%s'", tt.name)
// }
// })
// }
// }

func TestLoggingReadAndWrite(t *testing.T) {
tempFilePath := "temp_config.yaml"
Expand Down

0 comments on commit caf96b7

Please sign in to comment.