git-lfs/metafile/metafile_test.go

62 lines
1.3 KiB
Go
Raw Normal View History

package metafile
2013-10-04 13:48:08 +00:00
import (
"bytes"
"testing"
)
func TestEncode(t *testing.T) {
var buf bytes.Buffer
pointer := NewPointer("abc", 0)
n, err := Encode(&buf, pointer)
2013-10-04 13:48:08 +00:00
if err != nil {
t.Errorf("Error encoding: %s", err)
}
2013-11-08 16:10:29 +00:00
if n != len(MediaWarning)+4 {
2013-10-04 13:48:08 +00:00
t.Errorf("wrong number of written bytes")
}
header := make([]byte, len(MediaWarning))
buf.Read(header)
if head := string(header); head != string(MediaWarning) {
t.Errorf("Media warning not read: %s\n", head)
2013-10-04 13:48:08 +00:00
}
shabytes := make([]byte, 3)
buf.Read(shabytes)
if sha := string(shabytes); sha != "abc" {
t.Errorf("Invalid sha: %#v", sha)
}
}
func TestAlphaDecode(t *testing.T) {
2014-04-16 21:11:52 +00:00
buf := bytes.NewBufferString("# git-media\nabc\n")
if pointer, _ := Decode(buf); pointer.Oid != "abc" {
t.Errorf("Invalid SHA: %#v", pointer.Oid)
2014-04-16 21:11:52 +00:00
}
}
func TestAlphaDecodeExternal(t *testing.T) {
2014-04-16 21:11:52 +00:00
buf := bytes.NewBufferString("# external\nabc\n")
if pointer, _ := Decode(buf); pointer.Oid != "abc" {
t.Errorf("Invalid SHA: %#v", pointer.Oid)
2013-10-04 13:48:08 +00:00
}
}
func TestDecodeInvalid(t *testing.T) {
buf := bytes.NewBufferString("invalid stuff")
if _, err := Decode(buf); err == nil {
t.Errorf("Decoded invalid sha")
}
}
func TestAlphaDecodeWithValidHeaderNoSha(t *testing.T) {
buf := bytes.NewBufferString("# git-media")
if _, err := Decode(buf); err == nil {
t.Errorf("Decoded with header but no sha")
}
}