|
7 | 7 | "app/base/utils" |
8 | 8 | "testing" |
9 | 9 |
|
| 10 | + "github.com/google/uuid" |
10 | 11 | "github.com/stretchr/testify/assert" |
11 | 12 | ) |
12 | 13 |
|
@@ -95,3 +96,43 @@ func TestCleanUnusedAdvisories(t *testing.T) { |
95 | 96 | assert.Nil(t, err) |
96 | 97 | assert.Equal(t, beforeAdvCount-rh100count, afterAdvCount) |
97 | 98 | } |
| 99 | + |
| 100 | +func TestDeleteUnusedAdvisoriesKeptByAccountAdvisory(t *testing.T) { |
| 101 | + utils.SkipWithoutDB(t) |
| 102 | + core.SetupTestEnvironment() |
| 103 | + |
| 104 | + advisory := "CUSTOM-5678" |
| 105 | + customAdv := models.AdvisoryMetadata{ |
| 106 | + Name: advisory, |
| 107 | + Description: "Custom desc", |
| 108 | + Synopsis: "Custom syn", |
| 109 | + Summary: "Custom sum", |
| 110 | + Solution: utils.PtrString("Custom sol"), |
| 111 | + AdvisoryTypeID: 1, |
| 112 | + RebootRequired: false, |
| 113 | + Synced: false, |
| 114 | + } |
| 115 | + err := database.DB.Create(&customAdv).Error |
| 116 | + assert.Nil(t, err) |
| 117 | + |
| 118 | + aa := models.AccountAdvisory{ |
| 119 | + AdvisoryID: customAdv.ID, |
| 120 | + RhAccountID: 1, |
| 121 | + WorkspaceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"), |
| 122 | + SystemsApplicable: 1, |
| 123 | + SystemsInstallable: 0, |
| 124 | + } |
| 125 | + err = database.DB.Create(&aa).Error |
| 126 | + assert.Nil(t, err) |
| 127 | + |
| 128 | + deleteUnusedAdvisories() |
| 129 | + |
| 130 | + var count int64 |
| 131 | + err = database.DB.Model(models.AdvisoryMetadata{}).Where("name = ?", advisory).Count(&count).Error |
| 132 | + assert.Nil(t, err) |
| 133 | + assert.Equal(t, int64(1), count, "advisory with account_advisory row should not be deleted") |
| 134 | + |
| 135 | + // cleanup |
| 136 | + database.DB.Delete(&aa) |
| 137 | + database.DB.Delete(&customAdv) |
| 138 | +} |
0 commit comments