1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package csconfig
- import (
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/crowdsecurity/go-cs-lib/cstest"
- )
- func TestLoadCSCLI(t *testing.T) {
- tests := []struct {
- name string
- input *Config
- expected *CscliCfg
- expectedErr string
- }{
- {
- name: "basic valid configuration",
- input: &Config{
- ConfigPaths: &ConfigurationPaths{
- ConfigDir: "./testdata",
- DataDir: "./data",
- HubDir: "./hub",
- HubIndexFile: "./hub/.index.json",
- },
- Prometheus: &PrometheusCfg{
- Enabled: true,
- Level: "full",
- ListenAddr: "127.0.0.1",
- ListenPort: 6060,
- },
- },
- expected: &CscliCfg{
- ConfigDir: "./testdata",
- DataDir: "./data",
- HubDir: "./hub",
- HubIndexFile: "./hub/.index.json",
- PrometheusUrl: "http://127.0.0.1:6060/metrics",
- },
- },
- }
- for _, tc := range tests {
- tc := tc
- t.Run(tc.name, func(t *testing.T) {
- err := tc.input.loadCSCLI()
- cstest.RequireErrorContains(t, err, tc.expectedErr)
- if tc.expectedErr != "" {
- return
- }
- assert.Equal(t, tc.expected, tc.input.Cscli)
- })
- }
- }
|