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"
|
2024-03-04 13:22:53 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2022-10-17 12:17:23 +00:00
|
|
|
|
2023-07-28 14:35:08 +00:00
|
|
|
"github.com/crowdsecurity/go-cs-lib/cstest"
|
2020-07-28 13:38:48 +00:00
|
|
|
)
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
func TestNormalLoad(t *testing.T) {
|
2023-10-09 09:10:51 +00:00
|
|
|
_, _, err := NewConfig("./testdata/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-10-09 09:10:51 +00:00
|
|
|
_, _, err = NewConfig("./testdata/xxx.yaml", false, false, false)
|
2023-11-24 14:57:32 +00:00
|
|
|
require.EqualError(t, err, "while reading yaml file: open ./testdata/xxx.yaml: "+cstest.FileNotFoundMessage)
|
2020-11-30 09:37:17 +00:00
|
|
|
|
2023-10-09 09:10:51 +00:00
|
|
|
_, _, err = NewConfig("./testdata/simulation.yaml", false, false, false)
|
2023-11-24 14:57:32 +00:00
|
|
|
require.EqualError(t, err, "./testdata/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 {
|
2023-10-09 09:10:51 +00:00
|
|
|
name string
|
|
|
|
expected *Config
|
2020-11-30 09:37:17 +00:00
|
|
|
}{
|
|
|
|
{
|
2023-10-09 09:10:51 +00:00
|
|
|
name: "new configuration: basic",
|
|
|
|
expected: &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{}
|
2023-10-09 09:10:51 +00:00
|
|
|
assert.Equal(t, tc.expected, result)
|
2022-10-17 12:17:23 +00:00
|
|
|
})
|
2020-07-28 13:38:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-24 17:16:17 +00:00
|
|
|
|
|
|
|
func TestDefaultConfig(t *testing.T) {
|
|
|
|
x := NewDefaultConfig()
|
2023-10-09 09:10:51 +00:00
|
|
|
_, err := yaml.Marshal(x)
|
|
|
|
require.NoError(t, err, "failed marshaling config: %s", err)
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|