From fd22663cbbf4d81f08c43eb823d352f2d4ac8ff3 Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Tue, 25 Aug 2015 15:08:11 +0100 Subject: [PATCH] Allow file data to be provided as reader or []byte (useful for json) --- test/testutils.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/testutils.go b/test/testutils.go index 77561980..597032dc 100644 --- a/test/testutils.go +++ b/test/testutils.go @@ -9,6 +9,7 @@ package test // as if the test was in the same package (as usual) import ( + "bytes" "fmt" "io" "io/ioutil" @@ -185,8 +186,10 @@ type FileInput struct { Filename string // Size of file (required) Size int64 - // Input data (optional - if nil, placeholder data of Size will be created) - Data io.Reader + // Input data (optional, if provided will be source of data) + DataReader io.Reader + // Input data (optional, if provided will be source of data) + Data []byte } // Input for defining commits for test repo @@ -278,7 +281,10 @@ func (repo *Repo) AddCommits(inputs []*CommitInput) []*CommitOutput { } // Any files to write? for fi, infile := range input.Files { - inputData := infile.Data + inputData := infile.DataReader + if inputData == nil && infile.Data != nil { + inputData = bytes.NewReader(infile.Data) + } if inputData == nil { // Different data for each file but deterministic inputData = NewPlaceholderDataReader(int64(i*fi), infile.Size)