func (s *UtilsSuite) TestFingerprintMatchesOpenFailed(c *gc.C) { _, expected := s.newReader(c, "spam") matcher := context.FingerprintMatcher{ Open: s.matcher.Open, } failure := errors.New("<failed>") s.stub.SetErrors(failure) _, err := matcher.FingerprintMatches("some/filename.txt", expected) c.Check(errors.Cause(err), gc.Equals, failure) s.stub.CheckCallNames(c, "Open") }
func (s *UtilsSuite) TestFingerprintMatchesNotFound(c *gc.C) { _, expected := s.newReader(c, "spam") matcher := context.FingerprintMatcher{ Open: s.matcher.Open, } s.stub.SetErrors(os.ErrNotExist) matches, err := matcher.FingerprintMatches("some/filename.txt", expected) c.Assert(err, jc.ErrorIsNil) c.Check(matches, jc.IsFalse) s.stub.CheckCallNames(c, "Open") }
func (s *UtilsSuite) TestFingerprintMatchesOkay(c *gc.C) { r, expected := s.newReader(c, "spam") s.matcher.ReturnOpen = r s.matcher.ReturnGenerateFingerprint = expected matcher := context.FingerprintMatcher{ Open: s.matcher.Open, GenerateFingerprint: s.matcher.GenerateFingerprint, } matches, err := matcher.FingerprintMatches("some/filename.txt", expected) c.Assert(err, jc.ErrorIsNil) c.Check(matches, jc.IsTrue) }
func (s *UtilsSuite) TestFingerprintMatchesGenerateFingerprintFailed(c *gc.C) { r, expected := s.newReader(c, "spam") s.matcher.ReturnOpen = r matcher := context.FingerprintMatcher{ Open: s.matcher.Open, GenerateFingerprint: s.matcher.GenerateFingerprint, } failure := errors.New("<failed>") s.stub.SetErrors(nil, failure) _, err := matcher.FingerprintMatches("some/filename.txt", expected) c.Check(errors.Cause(err), gc.Equals, failure) s.stub.CheckCallNames(c, "Open", "GenerateFingerprint", "Close") }
func (s *UtilsSuite) TestFingerprintMatchesDepCalls(c *gc.C) { r, expected := s.newReader(c, "spam") s.matcher.ReturnOpen = r s.matcher.ReturnGenerateFingerprint = expected matcher := context.FingerprintMatcher{ Open: s.matcher.Open, GenerateFingerprint: s.matcher.GenerateFingerprint, } matches, err := matcher.FingerprintMatches("some/filename.txt", expected) c.Assert(matches, jc.IsTrue) c.Assert(err, jc.ErrorIsNil) s.stub.CheckCallNames(c, "Open", "GenerateFingerprint", "Close") s.stub.CheckCall(c, 0, "Open", "some/filename.txt") s.stub.CheckCall(c, 1, "GenerateFingerprint", r) }