MCPcopy Index your code
hub / github.com/cli/cli / StubWriteConfig

Function StubWriteConfig

internal/config/stub.go:134–167  ·  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

132// It then returns a function that will read in the config files into io.Writers.
133// It automatically cleans up environment variables and written files.
134func StubWriteConfig(t *testing.T) func(io.Writer, io.Writer) {
135 t.Helper()
136 tempDir := t.TempDir()
137 t.Setenv("GH_CONFIG_DIR", tempDir)
138 return func(wc io.Writer, wh io.Writer) {
139 config, err := os.Open(filepath.Join(tempDir, "config.yml"))
140 if err != nil {
141 return
142 }
143 defer config.Close()
144 configData, err := io.ReadAll(config)
145 if err != nil {
146 return
147 }
148 _, err = wc.Write(configData)
149 if err != nil {
150 return
151 }
152
153 hosts, err := os.Open(filepath.Join(tempDir, "hosts.yml"))
154 if err != nil {
155 return
156 }
157 defer hosts.Close()
158 hostsData, err := io.ReadAll(hosts)
159 if err != nil {
160 return
161 }
162 _, err = wh.Write(hostsData)
163 if err != nil {
164 return
165 }
166 }
167}

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