MCPcopy Index your code
hub / github.com/github/gh-aw / TestExecGH

Function TestExecGH

pkg/workflow/github_cli_test.go:18–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestExecGH(t *testing.T) {
19 tests := []struct {
20 name string
21 ghToken string
22 githubToken string
23 expectGHToken bool
24 expectValue string
25 }{
26 {
27 name: "GH_TOKEN is set",
28 ghToken: "gh-token-123",
29 githubToken: "",
30 expectGHToken: false, // Should use existing GH_TOKEN from environment
31 expectValue: "",
32 },
33 {
34 name: "GITHUB_TOKEN is set, GH_TOKEN is not",
35 ghToken: "",
36 githubToken: "github-token-456",
37 expectGHToken: true,
38 expectValue: "github-token-456",
39 },
40 {
41 name: "Both GH_TOKEN and GITHUB_TOKEN are set",
42 ghToken: "gh-token-123",
43 githubToken: "github-token-456",
44 expectGHToken: false, // Should prefer existing GH_TOKEN
45 expectValue: "",
46 },
47 {
48 name: "Neither GH_TOKEN nor GITHUB_TOKEN is set",
49 ghToken: "",
50 githubToken: "",
51 expectGHToken: false,
52 expectValue: "",
53 },
54 }
55
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 // Save original environment
59 originalGHToken, ghTokenWasSet := os.LookupEnv("GH_TOKEN")
60 originalGitHubToken, githubTokenWasSet := os.LookupEnv("GITHUB_TOKEN")
61 defer func() {
62 if ghTokenWasSet {
63 os.Setenv("GH_TOKEN", originalGHToken)
64 } else {
65 os.Unsetenv("GH_TOKEN")
66 }
67 if githubTokenWasSet {
68 os.Setenv("GITHUB_TOKEN", originalGitHubToken)
69 } else {
70 os.Unsetenv("GITHUB_TOKEN")
71 }
72 }()
73
74 // Set up test environment
75 if tt.ghToken != "" {

Callers

nothing calls this directly

Calls 3

SetenvMethod · 0.80
ExecGHFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected