Test a config YAML can be loaded

This commit is contained in:
Joel Speed 2019-06-08 22:52:59 +02:00
parent cf3eac0242
commit 6f9db420d5
No known key found for this signature in database
GPG Key ID: 6E80578D6751DEFB
2 changed files with 47 additions and 0 deletions

View File

@ -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)
}

View File

@ -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))
})
})
})