github.com/crowdsecurity/crowdsec@v1.6.1/pkg/csconfig/hub_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 TestLoadHub(t *testing.T) { 12 tests := []struct { 13 name string 14 input *Config 15 expected *LocalHubCfg 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 }, 28 expected: &LocalHubCfg{ 29 HubDir: "./hub", 30 HubIndexFile: "./hub/.index.json", 31 InstallDir: "./testdata", 32 InstallDataDir: "./data", 33 }, 34 }, 35 } 36 37 for _, tc := range tests { 38 tc := tc 39 t.Run(tc.name, func(t *testing.T) { 40 err := tc.input.loadHub() 41 cstest.RequireErrorContains(t, err, tc.expectedErr) 42 if tc.expectedErr != "" { 43 return 44 } 45 46 assert.Equal(t, tc.expected, tc.input.Hub) 47 }) 48 } 49 }