Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions infrastructure/file_settings_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func NewFileSettingsSource(
}

func (s *FileSettingsSource) PublicSSHKeyForUsername(string) (string, error) {
if !s.fs.FileExists(s.settingsFilePath) {
return "", bosherr.Error("File for settings source does not exist")
}
Comment thread
fmoehler marked this conversation as resolved.
return "", nil
}
Comment thread
fmoehler marked this conversation as resolved.

Expand Down
29 changes: 25 additions & 4 deletions infrastructure/file_settings_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,31 @@ var _ = Describe("FileSettingsSource", func() {
})

Describe("PublicSSHKeyForUsername", func() {
It("returns an empty string", func() {
publicKey, err := source.PublicSSHKeyForUsername("fake-username")
Expect(err).ToNot(HaveOccurred())
Expect(publicKey).To(Equal(""))
Context("when the settings file exists", func() {
BeforeEach(func() {
settingsFileName := "/fake-settings-file-path"
source = infrastructure.NewFileSettingsSource(settingsFileName, fs, logger)
err := fs.WriteFileString(settingsFileName, "{}")
Expect(err).NotTo(HaveOccurred())
})

It("returns an empty string", func() {
publicKey, err := source.PublicSSHKeyForUsername("fake-username")
Expect(err).ToNot(HaveOccurred())
Expect(publicKey).To(Equal(""))
})
})

Context("when the settings file does not exist", func() {
BeforeEach(func() {
source = infrastructure.NewFileSettingsSource("/missing-settings-file-path", fs, logger)
})

It("returns an error", func() {
_, err := source.PublicSSHKeyForUsername("fake-username")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("File for settings source does not exist"))
})
Comment thread
fmoehler marked this conversation as resolved.
})
})

Expand Down
Loading