@@ -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-
439333func 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
0 commit comments