MCPcopy Create free account
hub / github.com/cli/cli / StubWriteConfig

Function StubWriteConfig

internal/config/test.go:201–234  ·  view source on GitHub ↗

StubWriteConfig stubs out the filesystem where config file are written. It then returns a function that will read in the config files into io.Writers. It automatically cleans up environment variables and written files.

(t *testing.T)

Source from the content-addressed store, hash-verified

199// It then returns a function that will read in the config files into io.Writers.
200// It automatically cleans up environment variables and written files.
201func StubWriteConfig(t *testing.T) func(io.Writer, io.Writer) {
202 t.Helper()
203 tempDir := t.TempDir()
204 t.Setenv("GH_CONFIG_DIR", tempDir)
205 return func(wc io.Writer, wh io.Writer) {
206 config, err := os.Open(filepath.Join(tempDir, "config.yml"))
207 if err != nil {
208 return
209 }
210 defer config.Close()
211 configData, err := io.ReadAll(config)
212 if err != nil {
213 return
214 }
215 _, err = wc.Write(configData)
216 if err != nil {
217 return
218 }
219
220 hosts, err := os.Open(filepath.Join(tempDir, "hosts.yml"))
221 if err != nil {
222 return
223 }
224 defer hosts.Close()
225 hostsData, err := io.ReadAll(hosts)
226 if err != nil {
227 return
228 }
229 _, err = wh.Write(hostsData)
230 if err != nil {
231 return
232 }
233 }
234}

Callers 7

TestImportRunFunction · 0.92
TestNewCmdConfigSetFunction · 0.92
Test_setRunFunction · 0.92
NewIsolatedTestConfigFunction · 0.85

Calls 5

OpenMethod · 0.80
JoinMethod · 0.80
HelperMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.65

Tested by 6

TestImportRunFunction · 0.74
TestNewCmdConfigSetFunction · 0.74
Test_setRunFunction · 0.74