diff options
| author | lhchavez <[email protected]> | 2018-12-28 04:42:09 +0000 |
|---|---|---|
| committer | lhchavez <[email protected]> | 2018-12-28 04:42:09 +0000 |
| commit | ab3470030be17e024c96b7f00c757f8343ca70f5 (patch) | |
| tree | d437f0148a176050aad68ea6c8f6d8fcb9bb5889 | |
| parent | 344dc33faef98cb383ec0858e33b1aea695cbc1e (diff) | |
Add some tests
This should prevent regressions in the future.
| -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) { |
