logger.Error("TAG", "some %s info to log", "awesome") contents, err := fs.ReadFileString(logFile.Name()) Expect(err).ToNot(HaveOccurred()) expectedContent := expectedLogFormat("TAG", "ERROR - some awesome info to log") Expect(contents).To(MatchRegexp(expectedContent)) }) It("does not log at NONE level", func() { logger, logFile, err := New(boshlog.LevelNone, logFile.Name(), DefaultLogFileMode, fs) Expect(err).ToNot(HaveOccurred()) logger.Error("TAG", "some %s info to log", "awesome") contents, err := fs.ReadFileString(logFile.Name()) Expect(err).ToNot(HaveOccurred()) Expect(contents).To(Equal("")) }) It("errors if the file cannot be openned for writing", func() { fs.OpenFileErr = errors.New("fake-fs-error") _, _, err := New(boshlog.LevelNone, logFile.Name(), DefaultLogFileMode, fs) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fake-fs-error")) }) })
}) Context("when path is a file", func() { BeforeEach(func() { fs.RegisterOpenFile("/fake-archived-templates-path", &fakesys.FakeFile{ Contents: []byte("fake-archive-contents"), Stats: &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeFile}, }) }) It("returns sha1 of the file", func() { sha1, err := sha1Calculator.Calculate("/fake-archived-templates-path") Expect(err).ToNot(HaveOccurred()) Expect(sha1).To(Equal("4603db250d7b5b78dfe17869649784353177b549")) }) }) Context("when reading the file fails", func() { BeforeEach(func() { fs.OpenFileErr = errors.New("fake-open-file-error") }) It("returns an error", func() { _, err := sha1Calculator.Calculate("/fake-archived-templates-path") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fake-open-file-error")) }) }) }) })