Skip to content
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
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ formatters:
# with the given prefixes are grouped after 3rd-party packages.
# Default: []
local-prefixes:
- github.com/my/project
- github.com/GustavoCaso/meeseeks

golines:
# Target maximum line length.
Expand Down Expand Up @@ -106,7 +106,7 @@ linters:
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
- testableexamples # checks if examples are testable (have an expected output)
- testifylint # checks usage of github.com/stretchr/testify
# - testifylint # checks usage of github.com/stretchr/testify
# - testpackage # makes you use a separate _test package
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
Expand Down
12 changes: 6 additions & 6 deletions cmd/meeseeks/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMainCommands(t *testing.T) {
output := stdoutBuf.String() + stderrBuf.String()

if exitCode != 1 {
t.Errorf("Expected exit code 1, got %d", exitCode)
t.Fatalf("Expected exit code 1, got %d", exitCode)
}

expectedMessages := []string{
Expand All @@ -34,7 +34,7 @@ func TestMainCommands(t *testing.T) {

for _, msg := range expectedMessages {
if !strings.Contains(output, msg) {
t.Errorf("Expected output to contain %q, got %q", msg, output)
t.Fatalf("Expected output to contain %q, got %q", msg, output)
}
}
},
Expand All @@ -47,11 +47,11 @@ func TestMainCommands(t *testing.T) {
output := stdoutBuf.String() + stderrBuf.String()

if exitCode != 1 {
t.Errorf("Expected exit code 1, got %d", exitCode)
t.Fatalf("Expected exit code 1, got %d", exitCode)
}

if !strings.Contains(output, "Unknown command: unknown") {
t.Errorf("Expected unknown command error, got %q", output)
t.Fatalf("Expected unknown command error, got %q", output)
}
},
},
Expand All @@ -63,11 +63,11 @@ func TestMainCommands(t *testing.T) {
output := stdoutBuf.String() + stderrBuf.String()

if exitCode != 0 {
t.Errorf("Expected exit code %d, got %d", 0, exitCode)
t.Fatalf("Expected exit code %d, got %d", 0, exitCode)
}

if !strings.Contains(output, "meeseeks version 1.0.0") {
t.Errorf("Expected output to contain %q, got %q", "meeseeks version 1.0.0", output)
t.Fatalf("Expected output to contain %q, got %q", "meeseeks version 1.0.0", output)
}
},
},
Expand Down
30 changes: 15 additions & 15 deletions cmd/meeseeks/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func TestRunCommand_ConfigValidation(t *testing.T) {
output := stdoutBuf.String() + stderrBuf.String()

if exitCode != tt.expectedExit {
t.Errorf("Expected exit code %d, got %d", tt.expectedExit, exitCode)
t.Fatalf("Expected exit code %d, got %d", tt.expectedExit, exitCode)
}

if !strings.Contains(output, tt.errorMessage) {
t.Errorf("Expected error message %q, got %q", tt.errorMessage, output)
t.Fatalf("Expected error message %q, got %q", tt.errorMessage, output)
}
})
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestRunCommand_Foreground(t *testing.T) {

err = cmd.Start()
if err != nil {
t.Errorf("error starting in foreground: %s", err.Error())
t.Fatalf("error starting in foreground: %s", err.Error())
}

// Start goroutines to read from pipes and populate buffers
Expand Down Expand Up @@ -129,13 +129,13 @@ func TestRunCommand_Foreground(t *testing.T) {
if err != nil && !strings.Contains(err.Error(), "signal") &&
!strings.Contains(err.Error(), "interrupt") &&
!strings.Contains(err.Error(), "context deadline") {
t.Errorf("Unexpected error (ignoring interrupt/timeout): %v", err)
t.Fatalf("Unexpected error (ignoring interrupt/timeout): %v", err)
}

output := stdout.String() + stderr.String()
expected := "Started meeseeks program_count=1"
if !strings.Contains(output, expected) {
t.Errorf("Expected output to contain %q, got %q", expected, output)
t.Fatalf("Expected output to contain %q, got %q", expected, output)
}
}

Expand Down Expand Up @@ -179,17 +179,17 @@ func TestRunCommand_Detached(t *testing.T) {

output := stdout.String() + stderr.String()
if !strings.Contains(output, "Started meeseeks (detached)") {
t.Errorf("Expected `Started meeseeks (detached)`, got: %q", output)
t.Fatalf("Expected `Started meeseeks (detached)`, got: %q", output)
}

if _, err := os.Stat(expectedPidFile); os.IsNotExist(err) {
t.Errorf("PID file was not created at %s", expectedPidFile)
t.Fatalf("PID file was not created at %s", expectedPidFile)
}

time.Sleep(500 * time.Millisecond)

if _, err := os.Stat(expectedSocketPath); os.IsNotExist(err) {
t.Errorf("Socket file was not created at %s", expectedSocketPath)
t.Fatalf("Socket file was not created at %s", expectedSocketPath)
}

var stdoutBuf, stderrBuf bytes.Buffer
Expand All @@ -201,25 +201,25 @@ func TestRunCommand_Detached(t *testing.T) {
5*time.Second,
)
if exitCode != 0 {
t.Errorf("Expected exit code %d, got %d", 0, exitCode)
t.Fatalf("Expected exit code %d, got %d", 0, exitCode)
}
statusOutput := stdoutBuf.String() + stderrBuf.String()

if strings.Contains(statusOutput, "meeseeks server not running") {
t.Errorf("Status command could not connect to daemon: %q", statusOutput)
t.Fatalf("Status command could not connect to daemon: %q", statusOutput)
}

exitCode = runCLICommand(t, []string{"exit"}, nil, nil, 5*time.Second)
if exitCode != 0 {
t.Errorf("Expected exit code %d, got %d", 0, exitCode)
t.Fatalf("Expected exit code %d, got %d", 0, exitCode)
}

if _, err := os.Stat(expectedPidFile); !os.IsNotExist(err) {
t.Error("PID file still exists. Stoping meeseeks should remove the PID file")
t.Fatal("PID file still exists. Stoping meeseeks should remove the PID file")
}

if _, err := os.Stat(expectedSocketPath); !os.IsNotExist(err) {
t.Error("Socket file still exists. Stoping meeseeks should remove the Socket file")
t.Fatal("Socket file still exists. Stoping meeseeks should remove the Socket file")
}

var stdoutBuf2, stderrBuf2 bytes.Buffer
Expand All @@ -231,11 +231,11 @@ func TestRunCommand_Detached(t *testing.T) {
5*time.Second,
)
if exitCode != 1 {
t.Errorf("Expected exit code %d, got %d", 1, exitCode)
t.Fatalf("Expected exit code %d, got %d", 1, exitCode)
}
statusOutput = stdoutBuf2.String() + stderrBuf2.String()

if !strings.Contains(statusOutput, "meeseeks server not running") {
t.Error("Status command should not work after exiting meeseeks")
t.Fatal("Status command should not work after exiting meeseeks")
}
}
12 changes: 6 additions & 6 deletions cmd/meeseeks/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func ensureNoDaemonRunning(t *testing.T) {
expectedSocketPath := getSocketPath()

if _, err := os.Stat(expectedPidFile); !os.IsNotExist(err) {
t.Error("PID file still exists. Stoping meeseeks should remove the PID file")
t.Fatal("PID file still exists. Stoping meeseeks should remove the PID file")
}

if _, err := os.Stat(expectedSocketPath); !os.IsNotExist(err) {
t.Error("Socket file still exists. Stoping meeseeks should remove the Socket file")
t.Fatal("Socket file still exists. Stoping meeseeks should remove the Socket file")
}
}

Expand All @@ -166,11 +166,11 @@ func runCommandTests(t *testing.T, tests []commandTestCase) {
output := stdoutBuf.String() + stderrBuf.String()

if exitCode != tt.expectedExit {
t.Errorf("Expected exit code %d, got %d", tt.expectedExit, exitCode)
t.Fatalf("Expected exit code %d, got %d", tt.expectedExit, exitCode)
}

if !strings.Contains(output, tt.shouldContain) {
t.Errorf("Expected output to contain %q, got %q", tt.shouldContain, output)
t.Fatalf("Expected output to contain %q, got %q", tt.shouldContain, output)
}
})
}
Expand All @@ -183,12 +183,12 @@ func testCommandHelp(t *testing.T, command string, expectedMessages []string) {
output := stdoutBuf.String() + stderrBuf.String()

if exitCode != 0 {
t.Errorf("Expected exit code 0 for help, got %d", exitCode)
t.Fatalf("Expected exit code 0 for help, got %d", exitCode)
}

for _, msg := range expectedMessages {
if !strings.Contains(output, msg) {
t.Errorf("Expected help output to contain %q, got %q", msg, output)
t.Fatalf("Expected help output to contain %q, got %q", msg, output)
}
}
}
18 changes: 8 additions & 10 deletions cmd/meeseeks/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,20 @@ func TestCreateProgramFromConfig(t *testing.T) {

if tt.expectError {
if err == nil {
t.Errorf("Expected error but got none")
return
t.Fatalf("Expected error but got none")
}
if !strings.Contains(err.Error(), tt.errorMessage) {
t.Errorf("Expected error containing %q, got %q", tt.errorMessage, err.Error())
t.Fatalf("Expected error containing %q, got %q", tt.errorMessage, err.Error())
}
return
}

if err != nil {
t.Errorf("Unexpected error: %v", err)
return
t.Fatalf("Unexpected error: %v", err)
}

if prog.Name() != tt.expectedName {
t.Errorf("Expected name %q, got %q", tt.expectedName, prog.Name())
t.Fatalf("Expected name %q, got %q", tt.expectedName, prog.Name())
}
})
}
Expand All @@ -91,7 +89,7 @@ func TestGetMeeseeksDir(t *testing.T) {

result := getMeeseeksDir()
if result != customDir {
t.Errorf("Expected %q, got %q", customDir, result)
t.Fatalf("Expected %q, got %q", customDir, result)
}
})

Expand All @@ -101,7 +99,7 @@ func TestGetMeeseeksDir(t *testing.T) {
expected := filepath.Join(homeDir, ".meeseeks")

if result != expected {
t.Errorf("Expected %q, got %q", expected, result)
t.Fatalf("Expected %q, got %q", expected, result)
}
})
}
Expand All @@ -126,7 +124,7 @@ func TestPathFunctions(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
result := tt.function()
if result != tt.expected {
t.Errorf("Expected %q, got %q", tt.expected, result)
t.Fatalf("Expected %q, got %q", tt.expected, result)
}
})
}
Expand All @@ -151,7 +149,7 @@ func TestPathFunctions(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
result := tt.function()
if result != tt.expected {
t.Errorf("Expected %q, got %q", tt.expected, result)
t.Fatalf("Expected %q, got %q", tt.expected, result)
}
})
}
Expand Down
25 changes: 11 additions & 14 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,22 @@ func TestLoadConfig(t *testing.T) {

if tt.wantErr {
if err == nil {
t.Errorf("LoadConfig() expected error but got none")
t.Fatalf("LoadConfig() expected error but got none")
return
}
if tt.errContains != "" && !containsString(err.Error(), tt.errContains) {
t.Errorf("LoadConfig() error = %q, want error containing %q", err.Error(), tt.errContains)
t.Fatalf("LoadConfig() error = %q, want error containing %q", err.Error(), tt.errContains)
}
return
}

if err != nil {
t.Errorf("LoadConfig() unexpected error = %v", err)
t.Fatalf("LoadConfig() unexpected error = %v", err)
return
}

if !configsEqual(config, tt.expected) {
t.Errorf("LoadConfig() = %+v, want %+v", config, tt.expected)
t.Fatalf("LoadConfig() = %+v, want %+v", config, tt.expected)
}
})
}
Expand Down Expand Up @@ -261,22 +261,20 @@ func TestProgramConfig_GetInterval(t *testing.T) {

if tt.wantErr {
if err == nil {
t.Errorf("GetInterval() expected error but got none")
return
t.Fatalf("GetInterval() expected error but got none")
}
if tt.errContains != "" && !containsString(err.Error(), tt.errContains) {
t.Errorf("GetInterval() error = %q, want error containing %q", err.Error(), tt.errContains)
t.Fatalf("GetInterval() error = %q, want error containing %q", err.Error(), tt.errContains)
}
return
}

if err != nil {
t.Errorf("GetInterval() unexpected error = %v", err)
return
t.Fatalf("GetInterval() unexpected error = %v", err)
}

if duration != tt.expected {
t.Errorf("GetInterval() = %v, want %v", duration, tt.expected)
t.Fatalf("GetInterval() = %v, want %v", duration, tt.expected)
}
})
}
Expand Down Expand Up @@ -361,17 +359,16 @@ func TestConfig_Validate(t *testing.T) {

if tt.wantErr {
if err == nil {
t.Errorf("Validate() expected error but got none")
return
t.Fatalf("Validate() expected error but got none")
}
if tt.errContains != "" && !containsString(err.Error(), tt.errContains) {
t.Errorf("Validate() error = %q, want error containing %q", err.Error(), tt.errContains)
t.Fatalf("Validate() error = %q, want error containing %q", err.Error(), tt.errContains)
}
return
}

if err != nil {
t.Errorf("Validate() unexpected error = %v", err)
t.Fatalf("Validate() unexpected error = %v", err)
}
})
}
Expand Down
Loading