Fixing flaky software tests. (#19069)

Attempt to fix the flaky software tests. Because the insert order of
software is now not deterministic.
This commit is contained in:
Victor Lyuboslavsky 2024-05-16 14:49:09 -05:00 committed by GitHub
parent 185ec23ee2
commit f87906b1d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 16 deletions

View file

@ -8689,8 +8689,11 @@ func testHostHealth(t *testing.T, ds *Datastore) {
require.NoError(t, ds.LoadHostSoftware(context.Background(), h, false))
soft1 := h.Software[0]
if soft1.Name != "bar" {
soft1 = h.Software[1]
for _, item := range h.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
cpes := []fleet.SoftwareCPE{{SoftwareID: soft1.ID, CPE: "somecpe"}}
@ -8700,8 +8703,11 @@ func testHostHealth(t *testing.T, ds *Datastore) {
// Reload software so that 'GeneratedCPEID is set.
require.NoError(t, ds.LoadHostSoftware(context.Background(), h, false))
soft1 = h.Software[0]
if soft1.Name != "bar" {
soft1 = h.Software[1]
for _, item := range h.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
inserted, err := ds.InsertSoftwareVulnerability(

View file

@ -725,8 +725,11 @@ func (s *integrationTestSuite) TestVulnerableSoftware() {
require.NoError(t, s.ds.LoadHostSoftware(context.Background(), host, false))
soft1 := host.Software[0]
if soft1.Name != "bar" {
soft1 = host.Software[1]
for _, item := range host.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
cpes := []fleet.SoftwareCPE{{SoftwareID: soft1.ID, CPE: "somecpe"}}
@ -736,8 +739,11 @@ func (s *integrationTestSuite) TestVulnerableSoftware() {
// Reload software so that 'GeneratedCPEID is set.
require.NoError(t, s.ds.LoadHostSoftware(context.Background(), host, false))
soft1 = host.Software[0]
if soft1.Name != "bar" {
soft1 = host.Software[1]
for _, item := range host.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
inserted, err := s.ds.InsertSoftwareVulnerability(
@ -10862,8 +10868,11 @@ func (s *integrationTestSuite) TestHostHealth() {
require.NoError(t, s.ds.LoadHostSoftware(context.Background(), host, false))
soft1 := host.Software[0]
if soft1.Name != "bar" {
soft1 = host.Software[1]
for _, item := range host.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
cpes := []fleet.SoftwareCPE{{SoftwareID: soft1.ID, CPE: "somecpe"}}
@ -10873,8 +10882,11 @@ func (s *integrationTestSuite) TestHostHealth() {
// Reload software so that 'GeneratedCPEID is set.
require.NoError(t, s.ds.LoadHostSoftware(context.Background(), host, false))
soft1 = host.Software[0]
if soft1.Name != "bar" {
soft1 = host.Software[1]
for _, item := range host.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
inserted, err := s.ds.InsertSoftwareVulnerability(

View file

@ -7054,8 +7054,11 @@ func (s *integrationEnterpriseTestSuite) TestAllSoftwareTitles() {
require.NoError(t, s.ds.LoadHostSoftware(context.Background(), host, false))
soft1 := host.Software[0]
if soft1.Name != "bar" {
soft1 = host.Software[1]
for _, item := range host.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
cpes := []fleet.SoftwareCPE{{SoftwareID: soft1.ID, CPE: "somecpe"}}
@ -7065,8 +7068,11 @@ func (s *integrationEnterpriseTestSuite) TestAllSoftwareTitles() {
// Reload software so that 'GeneratedCPEID is set.
require.NoError(t, s.ds.LoadHostSoftware(context.Background(), host, false))
soft1 = host.Software[0]
if soft1.Name != "bar" {
soft1 = host.Software[1]
for _, item := range host.Software {
if item.Name == "bar" {
soft1 = item
break
}
}
inserted, err := s.ds.InsertSoftwareVulnerability(