Skip to content

Commit

Permalink
better config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HeavyHorst committed Nov 20, 2016
1 parent d4eaefc commit 3a22136
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 additions & 18 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package config

import (
"context"
"io/ioutil"
"os"
"testing"
Expand All @@ -20,23 +21,27 @@ import (
. "gopkg.in/check.v1"
)

const testFile string = `
log_level = "debug"
log_format = "text"
[[resource]]
[[resource.template]]
src = "/tmp/test12345.tmpl"
dst = "/tmp/test12345.cfg"
checkCmd = ""
reloadCmd = ""
mode = "0644"
[resource.backend]
[resource.backend.mock]
keys = ["/"]
watch = false
interval = 1
onetime = false
const (
testFile string = `
log_level = "debug"
log_format = "text"
include_dir = "/tmp/resource.d/"
`
resourceFile string = `
[[template]]
src = "/tmp/test12345.tmpl"
dst = "/tmp/test12345.cfg"
checkCmd = ""
reloadCmd = ""
mode = "0644"
[backend]
[backend.mock]
keys = ["/"]
watch = false
interval = 1
onetime = false
`
)

var expectedTemplates = []*template.Renderer{
&template.Renderer{
Expand All @@ -58,10 +63,12 @@ var expectedBackend = backends.Config{
}

var expected = Configuration{
LogLevel: "debug",
LogFormat: "text",
LogLevel: "debug",
LogFormat: "text",
IncludeDir: "/tmp/resource.d/",
Resource: []Resource{
Resource{
Name: "test.toml",
Template: expectedTemplates,
Backend: expectedBackend,
},
Expand All @@ -78,6 +85,16 @@ type FilterSuite struct {
var _ = Suite(&FilterSuite{})

func (s *FilterSuite) SetUpSuite(t *C) {
err := os.Mkdir("/tmp/resource.d", 0755)
if err != nil {
t.Error(err)
}

err = ioutil.WriteFile("/tmp/resource.d/test.toml", []byte(resourceFile), 0644)
if err != nil {
t.Error(err)
}

f3, err := ioutil.TempFile("/tmp", "")
if err != nil {
t.Error(err)
Expand All @@ -95,6 +112,10 @@ func (s *FilterSuite) TearDownSuite(t *C) {
if err != nil {
t.Log(err)
}
err = os.RemoveAll("/tmp/resource.d")
if err != nil {
t.Log(err)
}
}

func (s *FilterSuite) TestNewConf(t *C) {
Expand All @@ -104,3 +125,16 @@ func (s *FilterSuite) TestNewConf(t *C) {
}
t.Check(cfg, DeepEquals, expected)
}

func (s *FilterSuite) TestResourceInit(t *C) {
cfg, err := NewConfiguration(s.cfgPath)
if err != nil {
t.Error(err)
}

r, err := cfg.Resource[0].Init(context.Background(), nil)
if err != nil {
t.Error(err)
}
defer r.Close()
}

0 comments on commit 3a22136

Please sign in to comment.