Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Update the tests to use the new filters
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Jan 20, 2022
1 parent 344c08a commit 1decd4c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
2 changes: 0 additions & 2 deletions web/sap_systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func TestSAPSystemsListHandler(t *testing.T) {
AttachedDatabase: &models.SAPSystem{},
},
}, nil)
sapSystemsService.On("GetApplicationsCount").Return(1, nil)
sapSystemsService.On("GetAllApplicationsSIDs").Return([]string{"HA1"}, nil)
sapSystemsService.On("GetAllApplicationsTags").Return([]string{"tag1"}, nil)

Expand Down Expand Up @@ -139,7 +138,6 @@ func TestSAPDatabaseListHandler(t *testing.T) {
},
},
}, nil)
sapSystemsService.On("GetDatabasesCount").Return(1, nil)
sapSystemsService.On("GetAllDatabasesSIDs").Return([]string{"PRD"}, nil)
sapSystemsService.On("GetAllDatabasesTags").Return([]string{"tag1"}, nil)

Expand Down
16 changes: 8 additions & 8 deletions web/services/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ import (
)

func TestAggregatedCheckDataString(t *testing.T) {
aCritical := &AggregatedCheckData{
aCritical := &models.AggregatedCheckData{
PassingCount: 2,
WarningCount: 1,
CriticalCount: 1,
}

assert.Equal(t, aCritical.String(), "critical")

aWarning := &AggregatedCheckData{
aWarning := &models.AggregatedCheckData{
PassingCount: 2,
WarningCount: 1,
CriticalCount: 0,
}

assert.Equal(t, aWarning.String(), "warning")

aPassing := &AggregatedCheckData{
aPassing := &models.AggregatedCheckData{
PassingCount: 2,
WarningCount: 0,
CriticalCount: 0,
}

assert.Equal(t, aPassing.String(), "passing")

aUndefined := &AggregatedCheckData{
aUndefined := &models.AggregatedCheckData{
PassingCount: 0,
WarningCount: 0,
CriticalCount: 0,
Expand Down Expand Up @@ -392,13 +392,13 @@ func (suite *ChecksServiceTestSuite) TestChecksService_CreateChecksResult() {
func (suite *ChecksServiceTestSuite) TestChecksService_GetAggregatedChecksResultByHost() {
results, err := suite.checksService.GetAggregatedChecksResultByHost("group1")

expectedResults := map[string]*AggregatedCheckData{
"host1": &AggregatedCheckData{
expectedResults := map[string]*models.AggregatedCheckData{
"host1": &models.AggregatedCheckData{
PassingCount: 1,
WarningCount: 1,
CriticalCount: 0,
},
"host2": &AggregatedCheckData{
"host2": &models.AggregatedCheckData{
PassingCount: 1,
WarningCount: 0,
CriticalCount: 1,
Expand All @@ -412,7 +412,7 @@ func (suite *ChecksServiceTestSuite) TestChecksService_GetAggregatedChecksResult
func (suite *ChecksServiceTestSuite) TestChecksService_GetAggregatedChecksResultByCluster() {
results, err := suite.checksService.GetAggregatedChecksResultByCluster("group1")

expectedResults := &AggregatedCheckData{
expectedResults := &models.AggregatedCheckData{
PassingCount: 2,
WarningCount: 1,
CriticalCount: 1,
Expand Down
44 changes: 36 additions & 8 deletions web/services/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/trento-project/trento/test/helpers"
"github.com/trento-project/trento/web/entities"
"github.com/trento-project/trento/web/models"
"gorm.io/datatypes"
"gorm.io/gorm"
)

Expand All @@ -27,12 +28,13 @@ func TestClustersServiceTestSuite(t *testing.T) {
func (suite *ClustersServiceTestSuite) SetupSuite() {
suite.db = helpers.SetupTestDatabase(suite.T())

suite.db.AutoMigrate(entities.Cluster{}, entities.Host{}, models.Tag{}, models.SelectedChecks{}, models.ConnectionSettings{})
suite.db.AutoMigrate(entities.Cluster{}, entities.Host{}, models.Tag{}, models.SelectedChecks{}, models.ConnectionSettings{}, entities.ChecksResult{})
loadClustersFixtures(suite.db)
loadChecksFixtures(suite.db)
}

func (suite *ClustersServiceTestSuite) TearDownSuite() {
suite.db.Migrator().DropTable(entities.Cluster{}, entities.Host{}, models.Tag{}, models.SelectedChecks{}, models.ConnectionSettings{})
suite.db.Migrator().DropTable(entities.Cluster{}, entities.Host{}, models.Tag{}, models.SelectedChecks{}, models.ConnectionSettings{}, entities.ChecksResult{})
}

func (suite *ClustersServiceTestSuite) SetupTest() {
Expand Down Expand Up @@ -139,10 +141,36 @@ func loadClustersFixtures(db *gorm.DB) {
})
}

func loadChecksFixtures(db *gorm.DB) {
group1payloadCritical := `{"hosts":{"host1":{"reachable": true, "msg":""},"host2":{"reachable":false,"msg":"error connecting"}},
"checks":{"check1":{"hosts":{"host1":{"result":"passing"},"host2":{"result":"passing"}}},
"check2":{"hosts":{"host1":{"result":"warning"}, "host2":{"result":"critical"}}}}}`
db.Create(&entities.ChecksResult{
GroupID: "1",
Payload: datatypes.JSON([]byte(group1payloadCritical)),
})

group1payloadPassing := `{"hosts":{"host1":{"reachable": true, "msg":""},"host2":{"reachable":false,"msg":"error connecting"}},
"checks":{"check1":{"hosts":{"host1":{"result":"passing"},"host2":{"result":"passing"}}},
"check2":{"hosts":{"host1":{"result":"passing"}, "host2":{"result":"passing"}}}}}`
db.Create(&entities.ChecksResult{
GroupID: "1",
Payload: datatypes.JSON([]byte(group1payloadPassing)),
})

group2payloadPassing := `{"hosts":{"host1":{"reachable": true, "msg":""},"host2":{"reachable":false,"msg":"error connecting"}},
"checks":{"check1":{"hosts":{"host1":{"result":"passing"},"host2":{"result":"passing"}}},
"check2":{"hosts":{"host1":{"result":"passing"}, "host2":{"result":"passing"}}}}}`
db.Create(&entities.ChecksResult{
GroupID: "2",
Payload: datatypes.JSON([]byte(group2payloadPassing)),
})
}

func (suite *ClustersServiceTestSuite) TestClustersService_GetAll() {
suite.checksService.On("GetAggregatedChecksResultByCluster", "1").Return(&AggregatedCheckData{PassingCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByCluster", "2").Return(&AggregatedCheckData{WarningCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByCluster", "3").Return(&AggregatedCheckData{CriticalCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByCluster", "1").Return(&models.AggregatedCheckData{PassingCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByCluster", "2").Return(&models.AggregatedCheckData{WarningCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByCluster", "3").Return(&models.AggregatedCheckData{CriticalCount: 1}, nil)

clusters, _ := suite.clustersService.GetAll(nil, nil)

Expand Down Expand Up @@ -190,7 +218,7 @@ func (suite *ClustersServiceTestSuite) TestClustersService_GetAll() {
}

func (suite *ClustersServiceTestSuite) TestClustersService_GetAll_Filter() {
suite.checksService.On("GetAggregatedChecksResultByCluster", "1").Return(&AggregatedCheckData{PassingCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByCluster", "1").Return(&models.AggregatedCheckData{PassingCount: 1}, nil)

clusters, _ := suite.clustersService.GetAll(&ClustersFilter{
Name: []string{"cluster1"},
Expand All @@ -205,8 +233,8 @@ func (suite *ClustersServiceTestSuite) TestClustersService_GetAll_Filter() {
suite.Equal([]string{"tag1"}, clusters[0].Tags)
}
func (suite *ClustersServiceTestSuite) TestClustersService_GetByID() {
suite.checksService.On("GetAggregatedChecksResultByCluster", "1").Return(&AggregatedCheckData{PassingCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByHost", "1").Return(map[string]*AggregatedCheckData{
suite.checksService.On("GetAggregatedChecksResultByCluster", "1").Return(&models.AggregatedCheckData{PassingCount: 1}, nil)
suite.checksService.On("GetAggregatedChecksResultByHost", "1").Return(map[string]*models.AggregatedCheckData{
"host1": {PassingCount: 1},
}, nil)

Expand Down

0 comments on commit 1decd4c

Please sign in to comment.