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

Function StubWriteConfig

internal/config/test.go:169–202  ·  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

167// It then returns a function that will read in the config files into io.Writers.
168// It automatically cleans up environment variables and written files.
169func StubWriteConfig(t *testing.T) func(io.Writer, io.Writer) {
170 t.Helper()
171 tempDir := t.TempDir()
172 t.Setenv("GH_CONFIG_DIR", tempDir)
173 return func(wc io.Writer, wh io.Writer) {
174 config, err := os.Open(filepath.Join(tempDir, "config.yml"))
175 if err != nil {
176 return
177 }
178 defer config.Close()
179 configData, err := io.ReadAll(config)
180 if err != nil {
181 return
182 }
183 _, err = wc.Write(configData)
184 if err != nil {
185 return
186 }
187
188 hosts, err := os.Open(filepath.Join(tempDir, "hosts.yml"))
189 if err != nil {
190 return
191 }
192 defer hosts.Close()
193 hostsData, err := io.ReadAll(hosts)
194 if err != nil {
195 return
196 }
197 _, err = wh.Write(hostsData)
198 if err != nil {
199 return
200 }
201 }
202}

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