Skip to content

Commit e0e0a31

Browse files
committed
RHINENG-19230: remove baseline tests
1 parent 7212f17 commit e0e0a31

3 files changed

Lines changed: 5 additions & 195 deletions

File tree

base/database/testing.go

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -330,112 +330,6 @@ func DeleteNewlyAddedAdvisories(t *testing.T) {
330330
assert.Equal(t, int64(0), cnt)
331331
}
332332

333-
func CreateBaselineWithConfig(t *testing.T, name string, inventoryIDs []string,
334-
configBytes []byte, description *string) int64 {
335-
if name == "" {
336-
name = "temporary_baseline"
337-
}
338-
339-
temporaryBaseline := &models.Baseline{
340-
RhAccountID: 1, Name: name, Config: configBytes, Description: description,
341-
}
342-
343-
tx := DB.WithContext(base.Context).Begin()
344-
defer tx.Rollback()
345-
346-
if err := tx.Create(temporaryBaseline).Error; err != nil {
347-
assert.Nil(t, err)
348-
}
349-
350-
err := tx.Model(models.SystemPlatform{}).
351-
Where("rh_account_id = (?) AND inventory_id IN (?::uuid) AND EXISTS (SELECT * FROM inventory.hosts WHERE id IN (?))",
352-
1, inventoryIDs, inventoryIDs).
353-
Update("baseline_id", temporaryBaseline.ID).Error
354-
355-
assert.Nil(t, err)
356-
err = tx.Commit().Error
357-
assert.Nil(t, err)
358-
return temporaryBaseline.ID
359-
}
360-
361-
func CreateBaseline(t *testing.T, name string, inventoryIDs []string, description *string) int64 {
362-
configBytes := []byte(`{"to_time": "2021-01-01T12:00:00-04:00"}`)
363-
baselineID := CreateBaselineWithConfig(t, name, inventoryIDs, configBytes, description)
364-
return baselineID
365-
}
366-
367-
func DeleteBaseline(t *testing.T, baselineID int64) {
368-
tx := DB.WithContext(base.Context).Begin()
369-
defer tx.Rollback()
370-
371-
err := tx.Model(models.SystemPlatform{}).
372-
Where("rh_account_id = (?) AND baseline_id = (?)", 1, baselineID).
373-
Update("baseline_id", nil).Error
374-
375-
assert.Nil(t, err)
376-
377-
err = tx.Where(models.Baseline{ID: baselineID, RhAccountID: 1}).Delete(&models.Baseline{}).Error
378-
assert.Nil(t, err)
379-
380-
err = tx.Commit().Error
381-
assert.Nil(t, err)
382-
}
383-
384-
func CheckBaseline(t *testing.T, baselineID int64, inventoryIDs []string, config, name string, description *string) {
385-
type Baseline struct {
386-
ID int64 `query:"bl.id" gorm:"column:id"`
387-
Name string `json:"name" query:"bl.name" gorm:"column:name"`
388-
Config string `json:"config" query:"bl.config" gorm:"column:config"`
389-
Description *string `json:"description" query:"bl.description" gorm:"column:description"`
390-
}
391-
392-
type Associations struct {
393-
ID string `json:"system" query:"id"`
394-
}
395-
396-
var associations []Associations
397-
var baseline Baseline
398-
399-
err := DB.Table("system_platform as sp").Select("sp.inventory_id as id").
400-
Joins("JOIN inventory.hosts ih ON ih.id = sp.inventory_id").
401-
Where("sp.rh_account_id = (?) AND sp.baseline_id = (?)", 1, baselineID).Order("id").Find(&associations).Error
402-
403-
assert.Nil(t, err)
404-
405-
err = DB.Table("baseline as bl").
406-
Select("bl.id, bl.name, bl.config, bl.description").
407-
Where("bl.rh_account_id = (?) AND bl.id = (?)", 1, baselineID).Find(&baseline).Error
408-
409-
assert.Nil(t, err)
410-
411-
assert.Equal(t, baselineID, baseline.ID)
412-
assert.Equal(t, name, baseline.Name)
413-
assert.Equal(t, config, baseline.Config)
414-
if description == nil {
415-
assert.Equal(t, description, baseline.Description)
416-
} else {
417-
assert.Equal(t, *description, *baseline.Description)
418-
}
419-
420-
if len(inventoryIDs) == 0 {
421-
assert.Equal(t, len(associations), 0)
422-
} else {
423-
for index, inventoryID := range inventoryIDs {
424-
assert.Equal(t, associations[index].ID, inventoryID)
425-
}
426-
}
427-
}
428-
429-
func CheckBaselineDeleted(t *testing.T, baselineID int64) {
430-
var cntBaselines int64
431-
assert.Nil(t, DB.Model(&models.Baseline{}).Where("id = ?", baselineID).Count(&cntBaselines).Error)
432-
assert.Equal(t, 0, int(cntBaselines))
433-
434-
var cntSystems int64
435-
assert.Nil(t, DB.Model(&models.SystemPlatform{}).Where("baseline_id = ?", baselineID).Count(&cntSystems).Error)
436-
assert.Equal(t, 0, int(cntSystems))
437-
}
438-
439333
func GetAllSystems(t *testing.T) (systems []*models.SystemPlatform) {
440334
assert.Nil(t, DB.Model(&models.SystemPlatform{}).Order("rh_account_id").Scan(&systems).Error)
441335
return systems

evaluator/evaluate_baseline_test.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

manager/kafka/kafka_test.go

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package kafka
22

33
import (
44
"app/base/core"
5-
"app/base/database"
65
"app/base/mqueue"
76
"app/base/utils"
87
"app/manager/config"
@@ -12,15 +11,14 @@ import (
1211
"github.com/stretchr/testify/assert"
1312
)
1413

15-
func testEvaluateBaselineSystems(t *testing.T, baselineID *int64, accountID int,
16-
configUpdated bool, inventoryIDs []string) mqueue.PlatformEvent {
14+
func testRecalcSystems(t *testing.T, accountID int, inventoryIDs []string) mqueue.PlatformEvent {
1715
utils.SkipWithoutDB(t)
1816
core.SetupTestEnvironment()
1917
config.EnableTemplateChangeEval = true
2018

2119
writerMock := mqueue.MockKafkaWriter{}
2220
TryStartEvalQueue(mqueue.MockCreateKafkaWriter(&writerMock))
23-
inventoryAIDs := GetInventoryIDsToEvaluate(database.DB, baselineID, accountID, configUpdated, inventoryIDs)
21+
inventoryAIDs := InventoryIDs2InventoryAIDs(accountID, inventoryIDs)
2422
RecalcSystems(inventoryAIDs)
2523
utils.AssertEqualWait(t, 1, func() (exp, act interface{}) {
2624
return 1, len(writerMock.Messages)
@@ -30,38 +28,12 @@ func testEvaluateBaselineSystems(t *testing.T, baselineID *int64, accountID int,
3028
return event
3129
}
3230

33-
// Evaluate all baseline systems - config was updated, nothing added
34-
func TestEvaluateBaselineSystemsDefault(t *testing.T) {
35-
event := testEvaluateBaselineSystems(t, utils.PtrInt64(1), 1, true, nil)
36-
assert.Equal(t, 3, len(event.SystemIDs))
37-
assert.Equal(t, 1, event.AccountID)
38-
assert.Equal(t, "00000000-0000-0000-0000-000000000001", event.SystemIDs[0])
39-
assert.Equal(t, "00000000-0000-0000-0000-000000000002", event.SystemIDs[1])
40-
}
41-
42-
// Evaluate just updated systems - config was not updated
43-
func TestEvaluateBaselineUpdatedSystems(t *testing.T) {
31+
// Evaluate updated systems
32+
func TestRecalcUpdatedSystems(t *testing.T) {
4433
inventoryIDs := []string{"00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000004"}
45-
event := testEvaluateBaselineSystems(t, utils.PtrInt64(1), 1, false, inventoryIDs)
34+
event := testRecalcSystems(t, 1, inventoryIDs)
4635
assert.Equal(t, 2, len(event.SystemIDs))
4736
assert.Equal(t, 1, event.AccountID)
4837
assert.Equal(t, "00000000-0000-0000-0000-000000000001", event.SystemIDs[0])
4938
assert.Equal(t, "00000000-0000-0000-0000-000000000004", event.SystemIDs[1])
5039
}
51-
52-
// Evaluate both all baseline systems and added ones - config updated, systems added
53-
func TestEvaluateBaselineAllAndUpdatedSystems(t *testing.T) {
54-
inventoryIDs := []string{"00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000004"}
55-
event := testEvaluateBaselineSystems(t, utils.PtrInt64(1), 1, true, inventoryIDs)
56-
assert.Equal(t, 4, len(event.SystemIDs))
57-
assert.Equal(t, 1, event.AccountID)
58-
assert.Equal(t, "00000000-0000-0000-0000-000000000001", event.SystemIDs[0])
59-
assert.Equal(t, "00000000-0000-0000-0000-000000000002", event.SystemIDs[1])
60-
assert.Equal(t, "00000000-0000-0000-0000-000000000004", event.SystemIDs[2])
61-
}
62-
63-
// No systems needed to evaluate - e.g. just baseline name changed
64-
func TestEvaluateBaselineNoSystems(t *testing.T) {
65-
inventoryAIDs := GetInventoryIDsToEvaluate(database.DB, utils.PtrInt64(1), 1, false, nil)
66-
assert.Equal(t, 0, len(inventoryAIDs))
67-
}

0 commit comments

Comments
 (0)