summaryrefslogtreecommitdiff
path: root/odb_test.go
blob: bf1f847c0050b9eb5c3c2f16b6ceae418ca1901f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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")
	}
}