summaryrefslogtreecommitdiff
path: root/internal/timer/operations_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/timer/operations_test.go')
-rw-r--r--internal/timer/operations_test.go54
1 files changed, 27 insertions, 27 deletions
diff --git a/internal/timer/operations_test.go b/internal/timer/operations_test.go
index 0cb86fc..557631c 100644
--- a/internal/timer/operations_test.go
+++ b/internal/timer/operations_test.go
@@ -23,12 +23,12 @@ func TestStartTimer(t *testing.T) {
setup(t)
// Start the timer
- msg, err := StartTimer()
+ msg, err := StartTimer(false)
if err != nil {
- t.Fatalf("StartTimer() error = %v", err)
+ t.Fatalf("StartTimer(false) error = %v", err)
}
if msg != "Timer started." {
- t.Errorf("StartTimer() msg = %v, want %v", msg, "Timer started.")
+ t.Errorf("StartTimer(false) msg = %v, want %v", msg, "Timer started.")
}
// Check the state
@@ -41,12 +41,12 @@ func TestStartTimer(t *testing.T) {
}
// Try to start again
- msg, err = StartTimer()
+ msg, err = StartTimer(false)
if err != nil {
- t.Fatalf("StartTimer() error = %v", err)
+ t.Fatalf("StartTimer(false) error = %v", err)
}
if msg != "Timer is already running." {
- t.Errorf("StartTimer() msg = %v, want %v", msg, "Timer is already running.")
+ t.Errorf("StartTimer(false) msg = %v, want %v", msg, "Timer is already running.")
}
}
@@ -63,7 +63,7 @@ func TestStopTimer(t *testing.T) {
}
// Start and then stop the timer
- _, _ = StartTimer()
+ _, _ = StartTimer(false)
time.Sleep(10 * time.Millisecond) // Simulate work
msg, err = StopTimer()
if err != nil {
@@ -100,7 +100,7 @@ func TestGetStatus(t *testing.T) {
}
// Status when running
- _, _ = StartTimer()
+ _, _ = StartTimer(false)
msg, err = GetStatus()
if err != nil {
t.Fatalf("GetStatus() error = %v", err)
@@ -131,7 +131,7 @@ func TestGetRawStatus(t *testing.T) {
}
state.Running = true
state.StartTime = time.Now().Add(-2 * time.Second) // Set start time 2 seconds ago
- state.ElapsedTime = 0 // Reset elapsed time for this specific test
+ state.ElapsedTime = 0 // Reset elapsed time for this specific test
if err := state.Save(); err != nil {
t.Fatalf("Save() error = %v", err)
}
@@ -170,7 +170,7 @@ func TestGetRawMinutesStatus(t *testing.T) {
}
state.Running = true
state.StartTime = time.Now().Add(-2 * time.Minute) // Set start time 2 minutes ago
- state.ElapsedTime = 0 // Reset elapsed time for this specific test
+ state.ElapsedTime = 0 // Reset elapsed time for this specific test
if err := state.Save(); err != nil {
t.Fatalf("Save() error = %v", err)
}
@@ -189,7 +189,7 @@ func TestResetTimer(t *testing.T) {
setup(t)
// Start timer to create a state file
- _, _ = StartTimer()
+ _, _ = StartTimer(false)
// Reset the timer
msg, err := ResetTimer()
@@ -219,7 +219,7 @@ func TestTrackTime(t *testing.T) {
// Helper to create a mock task command
createMockTaskCommand := func(t *testing.T, shouldSucceed bool) {
t.Helper()
-
+
// Create a mock script that simulates the task command
mockScript := `#!/bin/sh
if [ "$1" = "add" ] && [ "$2" = "+timrtest" ]; then
@@ -235,16 +235,16 @@ echo "Invalid command"
exit 1
`
scriptContent := fmt.Sprintf(mockScript, shouldSucceed)
-
+
// Create temp directory for our mock
tempDir := t.TempDir()
mockPath := filepath.Join(tempDir, "task")
-
+
// Write the mock script
- if err := os.WriteFile(mockPath, []byte(scriptContent), 0755); err != nil {
+ if err := os.WriteFile(mockPath, []byte(scriptContent), 0o755); err != nil {
t.Fatalf("Failed to create mock script: %v", err)
}
-
+
// Update PATH to use our mock
oldPath := os.Getenv("PATH")
os.Setenv("PATH", tempDir+":"+oldPath)
@@ -256,22 +256,22 @@ exit 1
t.Run("TrackWithRunningTimer", func(t *testing.T) {
setup(t)
createMockTaskCommand(t, true)
-
+
// Start timer and let it run for a bit
state, _ := LoadState()
state.Running = true
state.StartTime = time.Now().Add(-5 * time.Minute)
state.ElapsedTime = 0
state.Save()
-
+
// We'll modify TrackTime to use +timrtest for testing
// For now, test with the actual implementation
// In a real scenario, we'd want to make the tag configurable
-
+
// Since we can't easily test the actual command execution,
// we'll test the error case when task command is not found
msg, err := TrackTime("test description")
-
+
// We expect an error because 'task' command likely doesn't exist
// or our mock won't match the exact command
if err == nil {
@@ -280,7 +280,7 @@ exit 1
t.Error("TrackTime() returned empty message on success")
}
}
-
+
// Verify timer was stopped
state, _ = LoadState()
if state.Running {
@@ -291,16 +291,16 @@ exit 1
t.Run("TrackWithStoppedTimer", func(t *testing.T) {
setup(t)
createMockTaskCommand(t, true)
-
+
// Set up a stopped timer with some elapsed time
state, _ := LoadState()
state.Running = false
state.ElapsedTime = 10 * time.Minute
state.Save()
-
+
// Try to track time
_, err := TrackTime("another test")
-
+
// We expect an error because task command likely doesn't exist
// but we can verify the state handling
if err == nil {
@@ -314,16 +314,16 @@ exit 1
t.Run("TrackWithZeroTime", func(t *testing.T) {
setup(t)
-
+
// Fresh timer with no elapsed time
state, _ := LoadState()
state.Running = false
state.ElapsedTime = 0
state.Save()
-
+
// Try to track with zero time
_, err := TrackTime("zero time test")
-
+
// Even with zero time, the command should be attempted
// We just verify no panic occurs
_ = err