File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ package downloader
2
+
3
+ import (
4
+ "context"
5
+ "os"
6
+ "path/filepath"
7
+ "testing"
8
+
9
+ "github.com/opencontainers/go-digest"
10
+ )
11
+
12
+ var a = digest .Algorithm ("sha256" )
13
+
14
+ func FuzzDownload (f * testing.F ) {
15
+ f .Fuzz (func (t * testing.T , fileContents []byte , checkDigest bool ) {
16
+ localFile := filepath .Join (t .TempDir (), "localFile" )
17
+ remoteFile := filepath .Join (t .TempDir (), "remoteFile" )
18
+ err := os .WriteFile (remoteFile , fileContents , 0o600 )
19
+ if err != nil {
20
+ t .Fatal (err )
21
+ }
22
+ testLocalFileURL := "file://" + remoteFile
23
+ if checkDigest {
24
+ d := a .FromBytes (fileContents )
25
+ _ , _ = Download (context .Background (),
26
+ localFile ,
27
+ testLocalFileURL ,
28
+ WithExpectedDigest (d ))
29
+ } else {
30
+ _ , _ = Download (context .Background (),
31
+ localFile ,
32
+ testLocalFileURL )
33
+ }
34
+ })
35
+ }
You can’t perform that action at this time.
0 commit comments