diff options
Diffstat (limited to 'plumbing/object_test.go')
-rw-r--r-- | plumbing/object_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/plumbing/object_test.go b/plumbing/object_test.go new file mode 100644 index 0000000..4d2dbe2 --- /dev/null +++ b/plumbing/object_test.go @@ -0,0 +1,46 @@ +package plumbing + +import . "gopkg.in/check.v1" + +type ObjectSuite struct{} + +var _ = Suite(&ObjectSuite{}) + +func (s *ObjectSuite) TestObjectTypeString(c *C) { + c.Assert(CommitObject.String(), Equals, "commit") + c.Assert(TreeObject.String(), Equals, "tree") + c.Assert(BlobObject.String(), Equals, "blob") + c.Assert(TagObject.String(), Equals, "tag") + c.Assert(REFDeltaObject.String(), Equals, "ref-delta") + c.Assert(OFSDeltaObject.String(), Equals, "ofs-delta") + c.Assert(AnyObject.String(), Equals, "any") + c.Assert(ObjectType(42).String(), Equals, "unknown") +} + +func (s *ObjectSuite) TestObjectTypeBytes(c *C) { + c.Assert(CommitObject.Bytes(), DeepEquals, []byte("commit")) +} + +func (s *ObjectSuite) TestObjectTypeValid(c *C) { + c.Assert(CommitObject.Valid(), Equals, true) + c.Assert(ObjectType(42).Valid(), Equals, false) +} + +func (s *ObjectSuite) TestParseObjectType(c *C) { + for s, e := range map[string]ObjectType{ + "commit": CommitObject, + "tree": TreeObject, + "blob": BlobObject, + "tag": TagObject, + "ref-delta": REFDeltaObject, + "ofs-delta": OFSDeltaObject, + } { + t, err := ParseObjectType(s) + c.Assert(err, IsNil) + c.Assert(e, Equals, t) + } + + t, err := ParseObjectType("foo") + c.Assert(err, Equals, ErrInvalidType) + c.Assert(t, Equals, InvalidObject) +} |