@@ -3,6 +3,7 @@ package fstest
33import (
44 "bytes"
55 "io"
6+ "math/rand"
67 "net"
78 "os"
89 "path/filepath"
@@ -23,12 +24,18 @@ func (a applyFn) Apply(root string) error {
2324// CreateFile returns a file applier which creates a file as the
2425// provided name with the given content and permission.
2526func CreateFile (name string , content []byte , perm os.FileMode ) Applier {
26- return WriteFileStream (name , bytes .NewReader (content ), perm )
27+ return writeFileStream (name , bytes .NewReader (content ), perm )
2728}
2829
29- // WriteFileStream returns a file applier which creates a file as the
30+ // CreateRandomFile returns a file applier which creates a file with random
31+ // content of the given size using the given seed and permission.
32+ func CreateRandomFile (name string , seed , size int64 , perm os.FileMode ) Applier {
33+ return writeFileStream (name , io .LimitReader (rand .New (rand .NewSource (seed )), size ), perm )
34+ }
35+
36+ // writeFileStream returns a file applier which creates a file as the
3037// provided name with the given content from the provided i/o stream and permission.
31- func WriteFileStream (name string , stream io.Reader , perm os.FileMode ) Applier {
38+ func writeFileStream (name string , stream io.Reader , perm os.FileMode ) Applier {
3239 return applyFn (func (root string ) (retErr error ) {
3340 fullPath := filepath .Join (root , name )
3441 f , err := os .OpenFile (fullPath , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , perm )
0 commit comments