2020-07-28 13:38:48 +00:00
|
|
|
package csconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-10-17 12:17:23 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/cstest"
|
2020-07-28 13:38:48 +00:00
|
|
|
)
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
func TestNormalLoad(t *testing.T) {
|
2023-01-11 08:50:46 +00:00
|
|
|
_, err := NewConfig("./tests/config.yaml", false, false, false)
|
2022-10-17 12:17:23 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-30 09:37:17 +00:00
|
|
|
|
2023-01-11 08:50:46 +00:00
|
|
|
_, err = NewConfig("./tests/xxx.yaml", false, false, false)
|
2022-10-17 12:17:23 +00:00
|
|
|
assert.EqualError(t, err, "while reading yaml file: open ./tests/xxx.yaml: "+cstest.FileNotFoundMessage)
|
2020-11-30 09:37:17 +00:00
|
|
|
|
2023-01-11 08:50:46 +00:00
|
|
|
_, err = NewConfig("./tests/simulation.yaml", false, false, false)
|
2022-05-18 08:08:37 +00:00
|
|
|
assert.EqualError(t, err, "./tests/simulation.yaml: yaml: unmarshal errors:\n line 1: field simulation not found in type csconfig.Config")
|
2020-07-28 13:38:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
func TestNewCrowdSecConfig(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2021-03-24 17:16:17 +00:00
|
|
|
expectedResult *Config
|
2020-11-30 09:37:17 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "new configuration: basic",
|
2021-03-24 17:16:17 +00:00
|
|
|
expectedResult: &Config{},
|
2020-11-30 09:37:17 +00:00
|
|
|
},
|
|
|
|
}
|
2022-10-17 12:17:23 +00:00
|
|
|
for _, tc := range tests {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
result := &Config{}
|
|
|
|
assert.Equal(t, tc.expectedResult, result)
|
|
|
|
})
|
2020-07-28 13:38:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-24 17:16:17 +00:00
|
|
|
|
|
|
|
func TestDefaultConfig(t *testing.T) {
|
|
|
|
x := NewDefaultConfig()
|
2022-10-17 12:17:23 +00:00
|
|
|
err := x.Dump()
|
|
|
|
require.NoError(t, err)
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|