clair/config/config_test.go
jgsqware 34e99466a6 config: not properly loaded error
When a wrong config file was used, it result in a panic.
Adding some check condition to validate the Unmarshaled configuration
before using it

fixes #134
2016-04-15 08:43:45 +02:00

42 lines
728 B
Go

package config
import (
"io/ioutil"
"log"
"os"
"testing"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/stretchr/testify/assert"
)
const wrongConfig = `
dummyKey:
wrong:true
`
func TestLoadWrongConfiguration(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "clair-config")
if err != nil {
log.Fatal(err)
}
defer os.Remove(tmpfile.Name()) // clean up
if _, err := tmpfile.Write([]byte(wrongConfig)); err != nil {
log.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
log.Fatal(err)
}
_, err = Load(tmpfile.Name())
assert.EqualError(t, err, cerrors.ErrConfigNotLoaded.Error())
}
func TestLoad(t *testing.T) {
_, err := Load("../config.example.yaml")
assert.NoError(t, err)
}