Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdlp committed Jul 7, 2016
1 parent d1c913f commit 68d366b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ type configData struct {
FavoriteHero string `yaml:"favorite_hero"`
}

var testConfigDataUnmarshalled = &configData{
HasBurrito: true,
FavoriteHero: "roadhog",
}

const (
dirMode os.FileMode = 0755
fileMode os.FileMode = 0644
Expand Down Expand Up @@ -102,6 +107,16 @@ var _ = Describe("Config", func() {
Ω(cfg.fileName()).Should(Equal("config.yaml"))
})

It("returns a default file name if FileFormat is nil", func() {
cfg.FileFormat = nil
Ω(cfg.fileName()).Should(Equal("config"))
})

It("returns a default file name if file extension is empty", func() {
cfg.FileFormat.Extension = ""
Ω(cfg.fileName()).Should(Equal("config"))
})

It("returns the right path for the system config", func() {
Ω(cfg.systemURI().Path).Should(Equal(systemPath))
})
Expand Down Expand Up @@ -145,5 +160,24 @@ var _ = Describe("Config", func() {
Ω(parseErr).Should(BeNil())
Ω(data).Should(Equal([]byte(testConfigData)))
})

It("checks to see if unmarshaller is set correctly", func() {
td := new(configData)
err := load(nil, f.Name(), td)
Ω(err).Should(Equal(ErrNilUnmarshaller))
})

It("checks to make sure dst is a pointer", func() {
td := new(configData)
err := load(yaml.Unmarshal, f.Name(), *td)
Ω(err).Should(Equal(ErrNotAPointer))
})

It("loads config data", func() {
td := new(configData)
err := load(yaml.Unmarshal, f.Name(), td)
Ω(err).Should(BeNil())
Ω(td).Should(Equal(testConfigDataUnmarshalled))
})
})
})

0 comments on commit 68d366b

Please sign in to comment.