(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestFileReader(t *testing.T) { |
| 11 | var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{ |
| 12 | Id: 1, |
| 13 | IsOn: true, |
| 14 | Options: map[string]interface{}{ |
| 15 | "dir": Tea.Root + "/caches", |
| 16 | }, |
| 17 | }) |
| 18 | |
| 19 | defer storage.Stop() |
| 20 | |
| 21 | err := storage.Init() |
| 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | |
| 26 | _, path, _ := storage.keyPath("my-key") |
| 27 | |
| 28 | fp, err := os.Open(path) |
| 29 | if err != nil { |
| 30 | if os.IsNotExist(err) { |
| 31 | t.Log("file '" + path + "' not exists") |
| 32 | return |
| 33 | } |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | defer func() { |
| 37 | _ = fp.Close() |
| 38 | }() |
| 39 | reader := NewFileReader(fp) |
| 40 | err = reader.Init() |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | |
| 45 | t.Log(reader.Status()) |
| 46 | |
| 47 | buf := make([]byte, 10) |
| 48 | err = reader.ReadHeader(buf, func(n int) (goNext bool, err error) { |
| 49 | t.Log("header:", string(buf[:n])) |
| 50 | return true, nil |
| 51 | }) |
| 52 | if err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | |
| 56 | err = reader.ReadBody(buf, func(n int) (goNext bool, err error) { |
| 57 | t.Log("body:", string(buf[:n])) |
| 58 | return true, nil |
| 59 | }) |
| 60 | if err != nil { |
| 61 | t.Fatal(err) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func TestFileReader_ReadHeader(t *testing.T) { |
| 66 | var path = "/Users/WorkSpace/EdgeProject/EdgeCache/p43/12/6b/126bbed90fc80f2bdfb19558948b0d49.cache" |
nothing calls this directly
no test coverage detected