Test a config YAML can be loaded
This commit is contained in:
parent
cf3eac0242
commit
6f9db420d5
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user