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

Function TestShouldRunCompileUpdateCheck

pkg/cli/compile_update_check_test.go:25–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestShouldRunCompileUpdateCheck(t *testing.T) {
26 origGetFilePath := getCompileUpdateCheckFilePathFunc
27 origIsTerminal := compileUpdateCheckIsTerminalFunc
28 t.Cleanup(func() {
29 getCompileUpdateCheckFilePathFunc = origGetFilePath
30 compileUpdateCheckIsTerminalFunc = origIsTerminal
31 })
32
33 tmpDir := t.TempDir()
34 lastCheckFile := filepath.Join(tmpDir, compileUpdateCheckFileName)
35 getCompileUpdateCheckFilePathFunc = func() string {
36 return lastCheckFile
37 }
38 compileUpdateCheckIsTerminalFunc = func() bool {
39 return true
40 }
41
42 t.Setenv("CI", "")
43 t.Setenv("CONTINUOUS_INTEGRATION", "")
44 t.Setenv("GITHUB_ACTIONS", "")
45 t.Setenv("GH_AW_MCP_SERVER", "")
46 t.Setenv(compileUpdateCheckDisableEnv, "")
47 assert.True(t, shouldRunCompileUpdateCheck(false), "check should run when not disabled")
48
49 require.NoError(
50 t,
51 os.WriteFile(lastCheckFile, []byte(time.Now().Format(time.RFC3339)), 0600),
52 "recent compile update marker should be written",
53 )
54 assert.False(t, shouldRunCompileUpdateCheck(false), "recent marker should suppress the background check")
55
56 t.Setenv(compileUpdateCheckDisableEnv, "1")
57 assert.False(t, shouldRunCompileUpdateCheck(false), "check should be disabled by environment variable")
58
59 t.Setenv(compileUpdateCheckDisableEnv, "")
60 assert.False(t, shouldRunCompileUpdateCheck(true), "check should be disabled by flag")
61
62 compileUpdateCheckIsTerminalFunc = func() bool {
63 return false
64 }
65 assert.False(t, shouldRunCompileUpdateCheck(false), "check should be disabled in non-interactive environments")
66}
67
68func TestRunCompileUpdateCheck(t *testing.T) {
69 originalVersion := GetVersion()

Callers

nothing calls this directly

Calls 2

SetenvMethod · 0.80

Tested by

no test coverage detected