MCPcopy Create free account
hub / github.com/github/gh-aw / TestCheckForUpdatesAsync_ContextCancellation

Function TestCheckForUpdatesAsync_ContextCancellation

pkg/cli/update_check_test.go:303–343  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

301}
302
303func TestCheckForUpdatesAsync_ContextCancellation(t *testing.T) {
304 // Test that async update check respects context cancellation
305 // Save original environment
306 origCI := os.Getenv("CI")
307 origGetLastCheckFilePath := getLastCheckFilePathFunc
308 defer func() {
309 os.Setenv("CI", origCI)
310 getLastCheckFilePathFunc = origGetLastCheckFilePath
311 }()
312
313 // Ensure we're not in CI mode
314 os.Unsetenv("CI")
315 os.Unsetenv("GITHUB_ACTIONS")
316 os.Unsetenv("CONTINUOUS_INTEGRATION")
317
318 // Create temporary directory for last check file
319 tmpDir := t.TempDir()
320 lastCheckFile := filepath.Join(tmpDir, lastCheckFileName)
321
322 // Override the function to use temp directory
323 getLastCheckFilePathFunc = func() string {
324 return lastCheckFile
325 }
326
327 // Create a cancellable context
328 ctx, cancel := context.WithCancel(context.Background())
329
330 // Cancel immediately
331 cancel()
332
333 // Call CheckForUpdatesAsync with cancelled context
334 CheckForUpdatesAsync(ctx, false, false)
335
336 // Wait a bit to ensure any goroutines would have had time to run
337 time.Sleep(200 * time.Millisecond)
338
339 // The update check should not have created a last check file
340 // because the context was cancelled
341 // Note: The check might still run if it started before cancellation,
342 // so we just verify no panics occurred
343}
344
345func TestFindLatestPublishedReleaseTag(t *testing.T) {
346 tests := []struct {

Callers

nothing calls this directly

Calls 4

CheckForUpdatesAsyncFunction · 0.85
GetenvMethod · 0.80
SetenvMethod · 0.80
BackgroundMethod · 0.80

Tested by

no test coverage detected