Skip to content

Commit

Permalink
Refactor gatherers package tests (#286)
Browse files Browse the repository at this point in the history
* Refactor verifypassword tests

* Refactor corosyncconf tests
  • Loading branch information
arbulu89 authored Nov 16, 2023
1 parent df9bce2 commit 2ec901a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
18 changes: 7 additions & 11 deletions internal/factsengine/gatherers/corosyncconf_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gatherers
package gatherers_test

import (
"testing"

"github.com/stretchr/testify/suite"
"github.com/trento-project/agent/internal/factsengine/gatherers"
"github.com/trento-project/agent/pkg/factsengine/entities"
"github.com/trento-project/agent/test/helpers"
)
Expand All @@ -16,13 +17,8 @@ func TestCorosyncConfTestSuite(t *testing.T) {
suite.Run(t, new(CorosyncConfTestSuite))
}

func (suite *CorosyncConfTestSuite) TestCorosyncConfDefault() {
c := NewDefaultCorosyncConfGatherer()
suite.Equal("/etc/corosync/corosync.conf", c.configFile)
}

func (suite *CorosyncConfTestSuite) TestCorosyncConfBasic() {
c := NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.basic"))
c := gatherers.NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.basic"))

factsRequest := []entities.FactRequest{
{
Expand Down Expand Up @@ -128,7 +124,7 @@ func (suite *CorosyncConfTestSuite) TestCorosyncConfBasic() {
}

func (suite *CorosyncConfTestSuite) TestCorosyncConfOneNode() {
c := NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.one_node"))
c := gatherers.NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.one_node"))

factsRequest := []entities.FactRequest{
{
Expand Down Expand Up @@ -160,7 +156,7 @@ func (suite *CorosyncConfTestSuite) TestCorosyncConfOneNode() {
}

func (suite *CorosyncConfTestSuite) TestCorosyncConfThreeNodes() {
c := NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.three_node"))
c := gatherers.NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.three_node"))

factsRequest := []entities.FactRequest{
{
Expand Down Expand Up @@ -202,7 +198,7 @@ func (suite *CorosyncConfTestSuite) TestCorosyncConfThreeNodes() {
}

func (suite *CorosyncConfTestSuite) TestCorosyncConfFileNotExists() {
c := NewCorosyncConfGatherer("not_found")
c := gatherers.NewCorosyncConfGatherer("not_found")

factsRequest := []entities.FactRequest{
{
Expand All @@ -225,7 +221,7 @@ func (suite *CorosyncConfTestSuite) TestCorosyncConfFileNotExists() {
}

func (suite *CorosyncConfTestSuite) TestCorosyncConfInvalid() {
c := NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.invalid"))
c := gatherers.NewCorosyncConfGatherer(helpers.GetFixturePath("gatherers/corosync.conf.invalid"))

factsRequest := []entities.FactRequest{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/factsengine/gatherers/verifypassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (g *VerifyPasswordGatherer) Gather(factsRequests []entities.FactRequest) ([

crypter := sha512crypt.New()
isPasswordWeak := false
var gatheringError *entities.FactGatheringError = nil
var gatheringError *entities.FactGatheringError
for _, password := range unsafePasswords {
passwordBytes := []byte(password)

Expand Down
11 changes: 6 additions & 5 deletions internal/factsengine/gatherers/verifypassword_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gatherers
package gatherers_test

import (
"testing"

"github.com/stretchr/testify/suite"
"github.com/trento-project/agent/internal/factsengine/gatherers"
"github.com/trento-project/agent/pkg/factsengine/entities"
utilsMocks "github.com/trento-project/agent/pkg/utils/mocks"
)
Expand All @@ -29,7 +30,7 @@ func (suite *PasswordTestSuite) TestPasswordGatherEqual() {
suite.mockExecutor.On("Exec", "getent", "shadow", "hacluster").Return(
shadow, nil)

verifyPasswordGatherer := NewVerifyPasswordGatherer(suite.mockExecutor)
verifyPasswordGatherer := gatherers.NewVerifyPasswordGatherer(suite.mockExecutor)

factRequests := []entities.FactRequest{
{
Expand Down Expand Up @@ -62,7 +63,7 @@ func (suite *PasswordTestSuite) TestPasswordGatherNotEqual() {
suite.mockExecutor.On("Exec", "getent", "shadow", "hacluster").Return(
shadow, nil)

verifyPasswordGatherer := NewVerifyPasswordGatherer(suite.mockExecutor)
verifyPasswordGatherer := gatherers.NewVerifyPasswordGatherer(suite.mockExecutor)

factRequests := []entities.FactRequest{
{
Expand Down Expand Up @@ -93,7 +94,7 @@ func (suite *PasswordTestSuite) TestPasswordGatherCryptError() {
suite.mockExecutor.On("Exec", "getent", "shadow", "hacluster").Return(
shadow, nil)

verifyPasswordGatherer := NewVerifyPasswordGatherer(suite.mockExecutor)
verifyPasswordGatherer := gatherers.NewVerifyPasswordGatherer(suite.mockExecutor)

factRequests := []entities.FactRequest{
{
Expand Down Expand Up @@ -123,7 +124,7 @@ func (suite *PasswordTestSuite) TestPasswordGatherCryptError() {
}

func (suite *PasswordTestSuite) TestPasswordGatherWrongArguments() {
verifyPasswordGatherer := &VerifyPasswordGatherer{} // nolint
verifyPasswordGatherer := gatherers.NewVerifyPasswordGatherer(suite.mockExecutor)

factRequests := []entities.FactRequest{
{
Expand Down

0 comments on commit 2ec901a

Please sign in to comment.