2013-09-11 12:17:45 -05:00
|
|
|
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!"
|
|
|
|
|
2013-09-21 17:05:37 -05:00
|
|
|
stream, error := odb.NewWriteStream(len(str), ObjectBlob)
|
2013-09-11 12:17:45 -05:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|