diff options
| author | Carlos MartÃn Nieto <[email protected]> | 2019-01-02 23:03:07 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-01-02 23:03:07 +0100 |
| commit | 7e9128bd581d2766672bb14ca6f13976a02764ac (patch) | |
| tree | b83e8f185ac4925efe640534a3eb98251905a9d6 /odb_test.go | |
| parent | 69175cb426cdb267609b6ede866abf4cc5e86504 (diff) | |
| parent | ab3470030be17e024c96b7f00c757f8343ca70f5 (diff) | |
Merge pull request #470 from lhchavez/fix-odbreadstream-read
Return io.EOF on OdbReadStream.Read()
Diffstat (limited to 'odb_test.go')
| -rw-r--r-- | odb_test.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/odb_test.go b/odb_test.go index 3d22fc9..090bdf6 100644 --- a/odb_test.go +++ b/odb_test.go @@ -3,6 +3,7 @@ package git import ( "errors" "io" + "io/ioutil" "testing" ) @@ -26,7 +27,7 @@ func TestOdbReadHeader(t *testing.T) { if err != nil { t.Fatalf("ReadHeader: %v", err) } - + if sz != uint64(len(data)) { t.Errorf("ReadHeader got size %d, want %d", sz, len(data)) } @@ -47,22 +48,29 @@ func TestOdbStream(t *testing.T) { str := "hello, world!" - stream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob) + writeStream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob) checkFatal(t, error) - n, error := io.WriteString(stream, str) + n, error := io.WriteString(writeStream, str) checkFatal(t, error) if n != len(str) { t.Fatalf("Bad write length %v != %v", n, len(str)) } - error = stream.Close() + error = writeStream.Close() checkFatal(t, error) expectedId, error := NewOid("30f51a3fba5274d53522d0f19748456974647b4f") checkFatal(t, error) - if stream.Id.Cmp(expectedId) != 0 { + if writeStream.Id.Cmp(expectedId) != 0 { t.Fatal("Wrong data written") } + + readStream, error := odb.NewReadStream(&writeStream.Id) + checkFatal(t, error) + data, error := ioutil.ReadAll(readStream) + if str != string(data) { + t.Fatalf("Wrong data read %v != %v", str, string(data)) + } } func TestOdbHash(t *testing.T) { |
