2021-03-24 17:16:17 +00:00
|
|
|
package csconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-10-09 09:10:51 +00:00
|
|
|
|
|
|
|
"github.com/crowdsecurity/go-cs-lib/cstest"
|
2021-03-24 17:16:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadCSCLI(t *testing.T) {
|
|
|
|
tests := []struct {
|
2023-10-09 09:10:51 +00:00
|
|
|
name string
|
|
|
|
input *Config
|
|
|
|
expected *CscliCfg
|
|
|
|
expectedErr string
|
2021-03-24 17:16:17 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "basic valid configuration",
|
2023-10-09 09:10:51 +00:00
|
|
|
input: &Config{
|
2021-03-24 17:16:17 +00:00
|
|
|
ConfigPaths: &ConfigurationPaths{
|
2023-10-09 09:10:51 +00:00
|
|
|
ConfigDir: "./testdata",
|
2021-03-24 17:16:17 +00:00
|
|
|
DataDir: "./data",
|
|
|
|
HubDir: "./hub",
|
|
|
|
HubIndexFile: "./hub/.index.json",
|
|
|
|
},
|
2023-11-24 14:57:32 +00:00
|
|
|
Prometheus: &PrometheusCfg{
|
|
|
|
Enabled: true,
|
|
|
|
Level: "full",
|
|
|
|
ListenAddr: "127.0.0.1",
|
|
|
|
ListenPort: 6060,
|
|
|
|
},
|
2021-03-24 17:16:17 +00:00
|
|
|
},
|
2023-10-09 09:10:51 +00:00
|
|
|
expected: &CscliCfg{
|
2024-01-25 11:53:20 +00:00
|
|
|
PrometheusUrl: "http://127.0.0.1:6060/metrics",
|
|
|
|
HubURLTemplate: defaultHubURLTemplate,
|
2021-03-24 17:16:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-10-09 09:10:51 +00:00
|
|
|
for _, tc := range tests {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2023-11-24 14:57:32 +00:00
|
|
|
err := tc.input.loadCSCLI()
|
2023-10-09 09:10:51 +00:00
|
|
|
cstest.RequireErrorContains(t, err, tc.expectedErr)
|
|
|
|
if tc.expectedErr != "" {
|
|
|
|
return
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 09:10:51 +00:00
|
|
|
assert.Equal(t, tc.expected, tc.input.Cscli)
|
|
|
|
})
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
}
|