(t *testing.T)
| 179 | } |
| 180 | |
| 181 | func TestUpdateLastCheckTime(t *testing.T) { |
| 182 | // Save original function |
| 183 | origGetLastCheckFilePath := getLastCheckFilePathFunc |
| 184 | defer func() { |
| 185 | getLastCheckFilePathFunc = origGetLastCheckFilePath |
| 186 | }() |
| 187 | |
| 188 | // Create temporary directory |
| 189 | tmpDir := t.TempDir() |
| 190 | lastCheckFile := filepath.Join(tmpDir, lastCheckFileName) |
| 191 | |
| 192 | // Override the function to use temp directory |
| 193 | getLastCheckFilePathFunc = func() string { |
| 194 | return lastCheckFile |
| 195 | } |
| 196 | |
| 197 | // Update the last check time |
| 198 | updateLastCheckTime() |
| 199 | |
| 200 | // Verify the file was created |
| 201 | if _, err := os.Stat(lastCheckFile); err != nil { |
| 202 | t.Fatalf("Last check file was not created: %v", err) |
| 203 | } |
| 204 | |
| 205 | // Read and verify the timestamp |
| 206 | data, err := os.ReadFile(lastCheckFile) |
| 207 | if err != nil { |
| 208 | t.Fatalf("Failed to read last check file: %v", err) |
| 209 | } |
| 210 | |
| 211 | timestamp, err := time.Parse(time.RFC3339, string(data)) |
| 212 | if err != nil { |
| 213 | t.Fatalf("Failed to parse timestamp: %v", err) |
| 214 | } |
| 215 | |
| 216 | // Check that the timestamp is recent (within 1 second) |
| 217 | if time.Since(timestamp) > time.Second { |
| 218 | t.Errorf("Timestamp is not recent: %v", timestamp) |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | func TestCheckForUpdatesWithNoCheckUpdateFlag(t *testing.T) { |
| 223 | // This test verifies that checkForUpdates respects the noCheckUpdate flag |
nothing calls this directly
no test coverage detected