crowdsec/pkg/csconfig/config_test.go
mmetc 98f2ac5e7c
fix #1385: .yaml.local (#1497)
Added support for .yaml.local files to override values in .yaml
2022-05-18 10:08:37 +02:00

59 lines
1.4 KiB
Go

package csconfig
import (
"fmt"
"log"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNormalLoad(t *testing.T) {
_, err := NewConfig("./tests/config.yaml", false, false)
if err != nil {
t.Fatalf("unexpected error %s", err)
}
_, err = NewConfig("./tests/xxx.yaml", false, false)
if runtime.GOOS != "windows" {
assert.EqualError(t, err, "while reading ./tests/xxx.yaml: open ./tests/xxx.yaml: no such file or directory")
} else {
assert.EqualError(t, err, "while reading ./tests/xxx.yaml: open ./tests/xxx.yaml: The system cannot find the file specified.")
}
_, err = NewConfig("./tests/simulation.yaml", false, false)
assert.EqualError(t, err, "./tests/simulation.yaml: yaml: unmarshal errors:\n line 1: field simulation not found in type csconfig.Config")
}
func TestNewCrowdSecConfig(t *testing.T) {
tests := []struct {
name string
expectedResult *Config
err string
}{
{
name: "new configuration: basic",
expectedResult: &Config{},
err: "",
},
}
for _, test := range tests {
result := &Config{}
isOk := assert.Equal(t, test.expectedResult, result)
if !isOk {
t.Fatalf("TEST '%s': NOK", test.name)
} else {
fmt.Printf("TEST '%s': OK\n", test.name)
}
}
}
func TestDefaultConfig(t *testing.T) {
x := NewDefaultConfig()
if err := x.Dump(); err != nil {
log.Fatal(err)
}
}