Expect(fakeBlobstore.GetError).ToNot(HaveOccurred()) Expect(fakeBlobstore.GetFileName).ToNot(Equal("")) }) It("reads the DNS records from the blobstore file", func() { response, err := syncDNS.Run("fake-blobstore-id", "fake-fingerprint") Expect(err).ToNot(HaveOccurred()) Expect(response).To(Equal("synced")) Expect(fakeBlobstore.GetError).ToNot(HaveOccurred()) Expect(fakeBlobstore.GetFileName).To(Equal("fake-blobstore-file-path")) Expect(fakeFileSystem.ReadFileError).ToNot(HaveOccurred()) }) It("fails reading the DNS records from the blobstore file", func() { fakeFileSystem.RegisterReadFileError("fake-blobstore-file-path", errors.New("fake-error")) response, err := syncDNS.Run("fake-blobstore-id", "fake-fingerprint") Expect(err).To(HaveOccurred()) Expect(response).To(Equal("")) Expect(err.Error()).To(ContainSubstring("Reading fileName")) }) It("deletes the file once read", func() { _, err := syncDNS.Run("fake-blobstore-id", "fake-fingerprint") Expect(err).ToNot(HaveOccurred()) Expect(fakeFileSystem.FileExists("fake-blobstore-file-path")).To(BeFalse()) }) It("logs when the dns blob file can't be deleted", func() {
Context("When the path to the agent's state is ''", func() { It("returns an error and a state object with false properties", func() { s, err = platform.NewBootstrapState(fs, "") Expect(s.Linux.HostsConfigured).To(BeFalse()) }) }) Context("When the agent cannot read the state file due to a failed disk", func() { It("returns an error and a state object with false properties", func() { fs.WriteFileString(path, `{ "hosts_configured": true, "hostname_configured": true }`) fs.RegisterReadFileError(path, errors.New("ENXIO: disk failed")) _, readerr := platform.NewBootstrapState(fs, path) Expect(readerr.Error()).To(ContainSubstring("disk failed")) }) }) Context("When the agent cannot parse the state file due to malformed JSON", func() { It("returns an error and a state object with false properties", func() { fs.WriteFileString(path, "malformed-JSON") _, readerr := platform.NewBootstrapState(fs, path) Expect(readerr).To(HaveOccurred()) })
Expect(fakeBlobstore.GetError).ToNot(HaveOccurred()) Expect(fakeBlobstore.GetFileName).ToNot(Equal("")) }) It("reads the DNS records from the blobstore file", func() { response, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2) Expect(err).ToNot(HaveOccurred()) Expect(response).To(Equal("synced")) Expect(fakeBlobstore.GetError).ToNot(HaveOccurred()) Expect(fakeBlobstore.GetFileName).To(Equal("fake-blobstore-file-path")) Expect(fakeFileSystem.ReadFileError).ToNot(HaveOccurred()) }) It("fails reading the DNS records from the blobstore file", func() { fakeFileSystem.RegisterReadFileError("fake-blobstore-file-path", errors.New("fake-error")) response, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2) Expect(err).To(HaveOccurred()) Expect(response).To(Equal("")) Expect(err.Error()).To(ContainSubstring("reading fake-blobstore-file-path from blobstore")) Expect(fakeFileSystem.FileExists("fake-blobstore-file-path")).To(BeFalse()) }) It("deletes the file once read", func() { _, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2) Expect(err).ToNot(HaveOccurred()) Expect(fakeFileSystem.FileExists("fake-blobstore-file-path")).To(BeFalse()) })