github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/resource/serialization_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package resource_test 5 6 import ( 7 "strings" 8 9 "github.com/juju/errors" 10 "github.com/juju/testing" 11 jc "github.com/juju/testing/checkers" 12 gc "gopkg.in/check.v1" 13 charmresource "gopkg.in/juju/charm.v6-unstable/resource" 14 15 "github.com/juju/juju/resource" 16 ) 17 18 type SerializationSuite struct { 19 testing.IsolationSuite 20 } 21 22 var _ = gc.Suite(&SerializationSuite{}) 23 24 func (s *SerializationSuite) TestDeserializeFingerprintOkay(c *gc.C) { 25 content := "some data\n..." 26 expected, err := charmresource.GenerateFingerprint(strings.NewReader(content)) 27 c.Assert(err, jc.ErrorIsNil) 28 29 fp, err := resource.DeserializeFingerprint(expected.Bytes()) 30 c.Assert(err, jc.ErrorIsNil) 31 32 c.Check(fp, jc.DeepEquals, expected) 33 } 34 35 func (s *SerializationSuite) TestDeserializeFingerprintInvalid(c *gc.C) { 36 _, err := resource.DeserializeFingerprint([]byte("<too short>")) 37 38 c.Check(err, jc.Satisfies, errors.IsNotValid) 39 } 40 41 func (s *SerializationSuite) TestDeserializeFingerprintZeroValue(c *gc.C) { 42 fp, err := resource.DeserializeFingerprint(nil) 43 c.Assert(err, jc.ErrorIsNil) 44 45 c.Check(fp, jc.DeepEquals, charmresource.Fingerprint{}) 46 }