From bbd03f60c1c2015edc850239ed2111e7f4cd8f0b Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 20 Jan 2016 12:52:21 +0100 Subject: [PATCH] Added testcase for using bool with ENV and default --- bool_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bool_test.go b/bool_test.go index 123f821..11a6f4b 100644 --- a/bool_test.go +++ b/bool_test.go @@ -1,6 +1,8 @@ package rconfig import ( + "os" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -39,3 +41,30 @@ var _ = Describe("Testing bool parsing", func() { Expect(cfg.Test4).To(Equal(false)) }) }) + +var _ = Describe("Testing to set bool from ENV with default", func() { + type t struct { + Test1 bool `default:"true" env:"TEST1"` + } + + var ( + err error + args []string + cfg t + ) + + BeforeEach(func() { + cfg = t{} + args = []string{} + }) + + JustBeforeEach(func() { + os.Unsetenv("TEST1") + err = parse(&cfg, args) + }) + + It("should not have errored", func() { Expect(err).NotTo(HaveOccurred()) }) + It("should have the expected values", func() { + Expect(cfg.Test1).To(Equal(true)) + }) +})