diff --git a/internal/cluster/sbd_test.go b/internal/cluster/sbd_test.go index 78408c51..00b9ebf1 100644 --- a/internal/cluster/sbd_test.go +++ b/internal/cluster/sbd_test.go @@ -2,12 +2,19 @@ package cluster import ( "errors" + "fmt" "testing" "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/utils/mocks" ) +const fixturesFolder = "../../test/fixtures/discovery/cluster/sbd/" + +func getFixtureFile(name string) string { + return fmt.Sprintf("%s/%s", fixturesFolder, name) +} + type SbdTestSuite struct { suite.Suite } @@ -277,7 +284,7 @@ func (suite *SbdTestSuite) TestLoadDeviceDataError() { } func (suite *SbdTestSuite) TestGetSBDConfig() { - sbdConfig, err := getSBDConfig("../../test/sbd_config") + sbdConfig, err := getSBDConfig(getFixtureFile("sbd_config")) expectedConfig := map[string]interface{}{ "SBD_PACEMAKER": "yes", @@ -312,7 +319,7 @@ func (suite *SbdTestSuite) TestNewSBD() { mockCommand.On("Exec", "/bin/sbd", "-d", "/dev/vdb", "dump").Return(mockSbdDump(), nil) mockCommand.On("Exec", "/bin/sbd", "-d", "/dev/vdb", "list").Return(mockSbdList(), nil) - s, err := NewSBD(mockCommand, "mycluster", "/bin/sbd", "../../test/sbd_config") + s, err := NewSBD(mockCommand, "mycluster", "/bin/sbd", getFixtureFile("sbd_config")) expectedSbd := SBD{ cluster: "mycluster", @@ -395,7 +402,7 @@ func (suite *SbdTestSuite) TestNewSBD() { func (suite *SbdTestSuite) TestNewSBDError() { mockCommand := new(mocks.CommandExecutor) s, err := NewSBD( - mockCommand, "mycluster", "/bin/sbd", "../../test/sbd_config_no_device") + mockCommand, "mycluster", "/bin/sbd", getFixtureFile("sbd_config_no_device")) expectedSbd := SBD{ //nolint cluster: "mycluster", @@ -421,7 +428,7 @@ func (suite *SbdTestSuite) TestNewSBDUnhealthyDevices() { mockCommand.On("Exec", "/bin/sbd", "-d", "/dev/vdb", "dump").Return(mockSbdDumpErr(), errors.New("error")) mockCommand.On("Exec", "/bin/sbd", "-d", "/dev/vdb", "list").Return(mockSbdListErr(), errors.New("error")) - s, err := NewSBD(mockCommand, "mycluster", "/bin/sbd", "../../test/sbd_config") + s, err := NewSBD(mockCommand, "mycluster", "/bin/sbd", getFixtureFile("sbd_config")) expectedSbd := SBD{ cluster: "mycluster", @@ -487,7 +494,7 @@ func (suite *SbdTestSuite) TestNewSBDQuotedDevices() { mockCommand.On("Exec", "/bin/sbd", "-d", "/dev/vdb", "list").Return(mockSbdList(), nil) s, err := NewSBD( - mockCommand, "mycluster", "/bin/sbd", "../../test/sbd_config_quoted_devices") + mockCommand, "mycluster", "/bin/sbd", getFixtureFile("sbd_config_quoted_devices")) suite.Equal(len(s.Devices), 2) suite.Equal("/dev/vdc", s.Devices[0].Device) diff --git a/internal/factsengine/gatherers/_todo/sbd_test.go b/internal/factsengine/gatherers/_todo/sbd_test.go index dd6ffee1..ef1ad9ab 100644 --- a/internal/factsengine/gatherers/_todo/sbd_test.go +++ b/internal/factsengine/gatherers/_todo/sbd_test.go @@ -1,6 +1,7 @@ package gatherers_test import ( + "fmt" "testing" "github.com/stretchr/testify/suite" @@ -8,6 +9,12 @@ import ( "github.com/trento-project/agent/internal/factsengine/gatherers" ) +const fixturesFolder = "../../../test/fixtures/discovery/cluster/sbd/" + +func getFixtureFile(name string) string { + return fmt.Sprintf("%s/%s", fixturesFolder, name) +} + type SBDGathererTestSuite struct { suite.Suite configurationFile string @@ -15,16 +22,14 @@ type SBDGathererTestSuite struct { func TestSBDGathererTestSuite(t *testing.T) { sbdSuite := new(SBDGathererTestSuite) - sbdSuite.configurationFile = "../../../test/sbd_config" + sbdSuite.configurationFile = getFixtureFile("sbd_config") suite.Run(t, sbdSuite) } func (suite *SBDGathererTestSuite) TestConfigFileCouldNotBeRead() { - const testSBDConfig = "../../../test/some-non-existent-sbd-config" - requestedFacts := []entities.FactRequest{} - gatherer := gatherers.NewSBDGatherer(testSBDConfig) + gatherer := gatherers.NewSBDGatherer(getFixtureFile("some-non-existent-sbd-config")) gatheredFacts, err := gatherer.Gather(requestedFacts) diff --git a/test/sbd_config b/test/fixtures/discovery/cluster/sbd/sbd_config similarity index 100% rename from test/sbd_config rename to test/fixtures/discovery/cluster/sbd/sbd_config diff --git a/test/sbd_config_no_device b/test/fixtures/discovery/cluster/sbd/sbd_config_no_device similarity index 100% rename from test/sbd_config_no_device rename to test/fixtures/discovery/cluster/sbd/sbd_config_no_device diff --git a/test/sbd_config_quoted_devices b/test/fixtures/discovery/cluster/sbd/sbd_config_quoted_devices similarity index 100% rename from test/sbd_config_quoted_devices rename to test/fixtures/discovery/cluster/sbd/sbd_config_quoted_devices