From 6f9db420d5dd8da3e845da4deccf6b19d508c80d Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Sat, 8 Jun 2019 22:52:59 +0200 Subject: [PATCH] Test a config YAML can be loaded --- pkg/apis/options/options.go | 4 +++ pkg/apis/options/options_test.go | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/pkg/apis/options/options.go b/pkg/apis/options/options.go index cc05343..a422985 100644 --- a/pkg/apis/options/options.go +++ b/pkg/apis/options/options.go @@ -53,6 +53,10 @@ func Load(config io.Reader, configType string, args []string) (*Options, error) // Read the configuration file if config != nil { + if configType == "" { + return nil, fmt.Errorf("config-type not set") + } + v.SetConfigType(configType) v.ReadConfig(config) } diff --git a/pkg/apis/options/options_test.go b/pkg/apis/options/options_test.go index b14d60e..4f273e6 100644 --- a/pkg/apis/options/options_test.go +++ b/pkg/apis/options/options_test.go @@ -1,8 +1,10 @@ package options import ( + "bytes" "io" "testing" + "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -20,6 +22,15 @@ var _ = Describe("Load", func() { var configType string var args []string + BeforeEach(func() { + // Make sure to clear previous test globals + opts = nil + err = nil + config = nil + configType = "" + args = []string{} + }) + JustBeforeEach(func() { opts, err = Load(config, configType, args) }) @@ -34,4 +45,36 @@ var _ = Describe("Load", func() { Expect(opts).To(Equal(defaultOpts)) }) }) + + Context("with a yaml configuration for cookies", func() { + BeforeEach(func() { + configType = "yaml" + config = bytes.NewBuffer([]byte(` + cookie: + name: cookie_name + secret: 123567890abcdef + domain: example.com + path: /path + expire: 12h + refresh: 1h + secure: false + httpOnly: false + `)) + }) + + It("sets the correct configuration", func() { + expected := &CookieOptions{ + Name: "cookie_name", + Secret: "123567890abcdef", + Domain: "example.com", + Path: "/path", + Expire: time.Duration(12) * time.Hour, + Refresh: time.Hour, + Secure: false, + HTTPOnly: false, + } + Expect(opts.Cookie).To(Equal(expected)) + }) + + }) })