MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / TestFileStorage_OpenWriter_HTTP

Function TestFileStorage_OpenWriter_HTTP

internal/caches/storage_file_test.go:148–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

146}
147
148func TestFileStorage_OpenWriter_HTTP(t *testing.T) {
149 if !testutils.IsSingleTesting() {
150 return
151 }
152
153 var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
154 Id: 1,
155 IsOn: true,
156 Options: map[string]interface{}{
157 "dir": Tea.Root + "/caches",
158 },
159 })
160
161 defer storage.Stop()
162
163 err := storage.Init()
164 if err != nil {
165 t.Fatal(err)
166 }
167 now := time.Now()
168 defer func() {
169 t.Log(time.Since(now).Seconds()*1000, "ms")
170 }()
171
172 writer, err := storage.OpenWriter("my-http-response", time.Now().Unix()+86400, 200, -1, -1, -1, false)
173 if err != nil {
174 t.Fatal(err)
175 }
176 t.Log(writer)
177
178 resp := &http.Response{
179 StatusCode: http.StatusOK,
180 Header: http.Header{
181 "Content-Type": []string{"text/html; charset=utf-8"},
182 "Last-Modified": []string{"Wed, 06 Jan 2021 10:03:29 GMT"},
183 "Server": []string{"CDN-Server"},
184 },
185 Body: io.NopCloser(bytes.NewBuffer([]byte("THIS IS HTTP BODY"))),
186 }
187
188 for k, v := range resp.Header {
189 for _, v1 := range v {
190 _, err = writer.WriteHeader([]byte(k + ":" + v1 + "\n"))
191 if err != nil {
192 t.Fatal(err)
193 }
194 }
195 }
196
197 buf := make([]byte, 1024)
198 for {
199 n, err := resp.Body.Read(buf)
200 if n > 0 {
201 _, err = writer.Write(buf[:n])
202 if err != nil {
203 t.Fatal(err)
204 }
205 }

Callers

nothing calls this directly

Calls 13

IsSingleTestingFunction · 0.92
NewFileStorageFunction · 0.85
LogMethod · 0.80
UnixMethod · 0.80
StopMethod · 0.65
InitMethod · 0.65
OpenWriterMethod · 0.65
WriteHeaderMethod · 0.65
ReadMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
HeaderSizeMethod · 0.65

Tested by

no test coverage detected