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

Function TestExecGHContext

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

Source from the content-addressed store, hash-verified

145}
146
147func TestExecGHContext(t *testing.T) {
148 tests := []struct {
149 name string
150 ghToken string
151 githubToken string
152 expectGHToken bool
153 expectValue string
154 }{
155 {
156 name: "GH_TOKEN is set with context",
157 ghToken: "gh-token-123",
158 githubToken: "",
159 expectGHToken: false,
160 expectValue: "",
161 },
162 {
163 name: "GITHUB_TOKEN is set with context",
164 ghToken: "",
165 githubToken: "github-token-456",
166 expectGHToken: true,
167 expectValue: "github-token-456",
168 },
169 {
170 name: "No tokens with context",
171 ghToken: "",
172 githubToken: "",
173 expectGHToken: false,
174 expectValue: "",
175 },
176 }
177
178 for _, tt := range tests {
179 t.Run(tt.name, func(t *testing.T) {
180 // Save original environment
181 originalGHToken, ghTokenWasSet := os.LookupEnv("GH_TOKEN")
182 originalGitHubToken, githubTokenWasSet := os.LookupEnv("GITHUB_TOKEN")
183 defer func() {
184 if ghTokenWasSet {
185 os.Setenv("GH_TOKEN", originalGHToken)
186 } else {
187 os.Unsetenv("GH_TOKEN")
188 }
189 if githubTokenWasSet {
190 os.Setenv("GITHUB_TOKEN", originalGitHubToken)
191 } else {
192 os.Unsetenv("GITHUB_TOKEN")
193 }
194 }()
195
196 // Set up test environment
197 if tt.ghToken != "" {
198 os.Setenv("GH_TOKEN", tt.ghToken)
199 } else {
200 os.Unsetenv("GH_TOKEN")
201 }
202 if tt.githubToken != "" {
203 os.Setenv("GITHUB_TOKEN", tt.githubToken)
204 } else {

Callers

nothing calls this directly

Calls 4

SetenvMethod · 0.80
BackgroundMethod · 0.80
ExecGHContextFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected