Fuzz must be run manually with the `-fuzz` flag to generate random test cases. By default, it only runs the added seed corpus cases. go test -fuzz=FuzzBytesToDataUpload
(f *testing.F)
| 110 | // By default, it only runs the added seed corpus cases. |
| 111 | // go test -fuzz=FuzzBytesToDataUpload |
| 112 | func FuzzBytesToDataUpload(f *testing.F) { |
| 113 | // Cases to always run in standard `go test` runs. |
| 114 | always := [][]byte{ |
| 115 | {}, |
| 116 | []byte("1"), |
| 117 | []byte("small"), |
| 118 | } |
| 119 | for _, data := range always { |
| 120 | f.Add(data) |
| 121 | } |
| 122 | |
| 123 | f.Fuzz(func(t *testing.T, data []byte) { |
| 124 | first, chunks, err := proto.BytesToDataUpload(proto.DataUploadType_UPLOAD_TYPE_MODULE_FILES, data) |
| 125 | if err != nil { |
| 126 | // Data exceeds MaxFileSize, which is expected for large fuzz inputs. |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | builder, err := proto.NewDataBuilder(first) |
| 131 | require.NoError(t, err) |
| 132 | |
| 133 | var done bool |
| 134 | for _, chunk := range chunks { |
| 135 | require.False(t, done) |
| 136 | done, err = builder.Add(chunk) |
| 137 | require.NoError(t, err) |
| 138 | } |
| 139 | |
| 140 | if len(chunks) > 0 { |
| 141 | require.True(t, done) |
| 142 | } |
| 143 | |
| 144 | finalData, err := builder.Complete() |
| 145 | require.NoError(t, err) |
| 146 | require.Equal(t, data, finalData) |
| 147 | }) |
| 148 | } |
| 149 | |
| 150 | // TestBytesToDataUpload tests the BytesToDataUpload function and the DataBuilder |
| 151 | // with large random data uploads. |
nothing calls this directly
no test coverage detected