MCPcopy
hub / github.com/caddyserver/caddy / generateRandFile

Function generateRandFile

modules/caddyhttp/reverseproxy/fastcgi/client_test.go:182–210  ·  view source on GitHub ↗
(size int)

Source from the content-addressed store, hash-verified

180}
181
182func generateRandFile(size int) (p string, m string) {
183 p = filepath.Join(os.TempDir(), "fcgict"+strconv.Itoa(rand.Int()))
184
185 // open output file
186 fo, err := os.Create(p)
187 if err != nil {
188 panic(err)
189 }
190 // close fo on exit and check for its returned error
191 defer func() {
192 if err := fo.Close(); err != nil {
193 panic(err)
194 }
195 }()
196
197 h := md5.New()
198 for i := 0; i < size/16; i++ {
199 buf := make([]byte, 16)
200 binary.PutVarint(buf, rand.Int64())
201 if _, err := fo.Write(buf); err != nil {
202 log.Printf("[ERROR] failed to write buffer: %v\n", err)
203 }
204 if _, err := h.Write(buf); err != nil {
205 log.Printf("[ERROR] failed to write buffer: %v\n", err)
206 }
207 }
208 m = fmt.Sprintf("%x", h.Sum(nil))
209 return p, m
210}
211
212func DisabledTest(t *testing.T) {
213 // TODO: test chunked reader

Callers 1

DisabledTestFunction · 0.85

Calls 3

IntMethod · 0.45
CloseMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected