github.com/crowdsecurity/crowdsec@v1.6.1/pkg/csconfig/cscli_test.go (about) 1 package csconfig 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/crowdsecurity/go-cs-lib/cstest" 9 ) 10 11 func TestLoadCSCLI(t *testing.T) { 12 tests := []struct { 13 name string 14 input *Config 15 expected *CscliCfg 16 expectedErr string 17 }{ 18 { 19 name: "basic valid configuration", 20 input: &Config{ 21 ConfigPaths: &ConfigurationPaths{ 22 ConfigDir: "./testdata", 23 DataDir: "./data", 24 HubDir: "./hub", 25 HubIndexFile: "./hub/.index.json", 26 }, 27 Prometheus: &PrometheusCfg{ 28 Enabled: true, 29 Level: "full", 30 ListenAddr: "127.0.0.1", 31 ListenPort: 6060, 32 }, 33 }, 34 expected: &CscliCfg{ 35 PrometheusUrl: "http://127.0.0.1:6060/metrics", 36 HubURLTemplate: defaultHubURLTemplate, 37 }, 38 }, 39 } 40 41 for _, tc := range tests { 42 tc := tc 43 t.Run(tc.name, func(t *testing.T) { 44 err := tc.input.loadCSCLI() 45 cstest.RequireErrorContains(t, err, tc.expectedErr) 46 if tc.expectedErr != "" { 47 return 48 } 49 50 assert.Equal(t, tc.expected, tc.input.Cscli) 51 }) 52 } 53 }