hub_test.go 956 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package csconfig
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/crowdsecurity/go-cs-lib/cstest"
  6. )
  7. func TestLoadHub(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. input *Config
  11. expected *LocalHubCfg
  12. expectedErr string
  13. }{
  14. {
  15. name: "basic valid configuration",
  16. input: &Config{
  17. ConfigPaths: &ConfigurationPaths{
  18. ConfigDir: "./testdata",
  19. DataDir: "./data",
  20. HubDir: "./hub",
  21. HubIndexFile: "./hub/.index.json",
  22. },
  23. },
  24. expected: &LocalHubCfg{
  25. HubDir: "./hub",
  26. HubIndexFile: "./hub/.index.json",
  27. InstallDir: "./testdata",
  28. InstallDataDir: "./data",
  29. },
  30. },
  31. }
  32. for _, tc := range tests {
  33. tc := tc
  34. t.Run(tc.name, func(t *testing.T) {
  35. err := tc.input.loadHub()
  36. cstest.RequireErrorContains(t, err, tc.expectedErr)
  37. if tc.expectedErr != "" {
  38. return
  39. }
  40. assert.Equal(t, tc.expected, tc.input.Hub)
  41. })
  42. }
  43. }