summaryrefslogtreecommitdiff
path: root/odb_test.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2013-09-11 19:17:45 +0200
committerCarlos Martín Nieto <[email protected]>2013-09-11 19:25:40 +0200
commit621397026ce94dc3a536b7dbdde31ad00b0b14a8 (patch)
tree6dc4babaa434c35c6feff31c232dc61b4a06b20b /odb_test.go
parent3cbfdf37f48c7b2f8726ad7e60a963cae1d8fd21 (diff)
Wrap the odb streams
The interface to these streams should be what you expect from Go, and both have Write and Close functions so they implement Reader/ReadCloser and Write/WriteCloser respectively.
Diffstat (limited to 'odb_test.go')
-rw-r--r--odb_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/odb_test.go b/odb_test.go
new file mode 100644
index 0000000..bf1f847
--- /dev/null
+++ b/odb_test.go
@@ -0,0 +1,35 @@
+package git
+
+import (
+ "io"
+ "os"
+ "testing"
+)
+
+func TestOdbStream(t *testing.T) {
+ repo := createTestRepo(t)
+ defer os.RemoveAll(repo.Workdir())
+ _, _ = seedTestRepo(t, repo)
+
+ odb, error := repo.Odb()
+ checkFatal(t, error)
+
+ str := "hello, world!"
+
+ stream, error := odb.NewWriteStream(len(str), OBJ_BLOB)
+ checkFatal(t, error)
+ n, error := io.WriteString(stream, str)
+ checkFatal(t, error)
+ if n != len(str) {
+ t.Fatalf("Bad write length %v != %v", n, len(str))
+ }
+
+ error = stream.Close()
+ checkFatal(t, error)
+
+ expectedId, error := NewOidFromString("30f51a3fba5274d53522d0f19748456974647b4f")
+ checkFatal(t, error)
+ if stream.Id.Cmp(expectedId) != 0 {
+ t.Fatal("Wrong data written")
+ }
+} \ No newline at end of file