-
Notifications
You must be signed in to change notification settings - Fork 5
/
maketestsink.go
53 lines (49 loc) 路 1.14 KB
/
maketestsink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package checker
import (
"fmt"
"math/rand"
"github.com/itchio/savior"
"github.com/itchio/savior/semirandom"
)
func MakeTestSink() *Sink {
return MakeTestSinkAdvanced(10)
}
func MakeTestSinkAdvanced(numEntries int) *Sink {
sink := NewSink()
rng := rand.New(rand.NewSource(0xf617a899))
for i := 0; i < numEntries; i++ {
if rng.Intn(100) < 10 {
// ok, make a symlink
name := fmt.Sprintf("symlink-%d", i)
sink.Items[name] = &Item{
Entry: &savior.Entry{
CanonicalPath: name,
Kind: savior.EntryKindDir,
Linkname: fmt.Sprintf("target-%d", i*2),
},
}
} else if rng.Intn(100) < 20 {
// ok, make a dir
name := fmt.Sprintf("dir-%d", i)
sink.Items[name] = &Item{
Entry: &savior.Entry{
CanonicalPath: name,
Kind: savior.EntryKindDir,
},
}
} else {
// ok, make a file
size := rng.Int63n(4 * 1024 * 1024)
name := fmt.Sprintf("file-%d", i)
sink.Items[name] = &Item{
Entry: &savior.Entry{
CanonicalPath: name,
Kind: savior.EntryKindFile,
UncompressedSize: size,
},
Data: semirandom.Bytes(size),
}
}
}
return sink
}