(f *testing.F)
| 28 | ) |
| 29 | |
| 30 | func FuzzFetcher(f *testing.F) { |
| 31 | f.Fuzz(func(t *testing.T, data []byte) { |
| 32 | dataLen := len(data) |
| 33 | if dataLen == 0 { |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 38 | rw.Header().Set("content-range", fmt.Sprintf("bytes %d-%d/%d", 0, dataLen-1, dataLen)) |
| 39 | rw.Header().Set("content-length", strconv.Itoa(dataLen)) |
| 40 | rw.Write(data) |
| 41 | })) |
| 42 | defer s.Close() |
| 43 | |
| 44 | u, err := url.Parse(s.URL) |
| 45 | if err != nil { |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | f := dockerFetcher{&dockerBase{ |
| 50 | repository: "nonempty", |
| 51 | }} |
| 52 | host := RegistryHost{ |
| 53 | Client: s.Client(), |
| 54 | Host: u.Host, |
| 55 | Scheme: u.Scheme, |
| 56 | Path: u.Path, |
| 57 | } |
| 58 | |
| 59 | ctx := context.Background() |
| 60 | req := f.request(host, http.MethodGet) |
| 61 | rc, _, err := f.open(ctx, req, "", 0, true) |
| 62 | if err != nil { |
| 63 | return |
| 64 | } |
| 65 | b, err := io.ReadAll(rc) |
| 66 | if err != nil { |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | expected := data |
| 71 | if len(b) != len(expected) { |
| 72 | t.Fatal("len of request is not equal to len of expected but should be") |
| 73 | } |
| 74 | }) |
| 75 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…