Skip to content

Commit

Permalink
Move sbd test fixture files to better folder
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Sep 21, 2022
1 parent 2286ba1 commit e5d75d1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
17 changes: 12 additions & 5 deletions internal/cluster/sbd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions internal/factsengine/gatherers/_todo/sbd_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
package gatherers_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/suite"
"github.com/trento-project/agent/internal/factsengine/entities"
"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
}

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)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e5d75d1

Please sign in to comment.