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

Function StubWriteConfig

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

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

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