Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test error checking #478

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func TestReportingServerExport(t *testing.T) {
},
}

reportIds := suite.InsertInspecReports(reports)
reportIds, err := suite.InsertInspecReports(reports)
require.NoError(t, err)

defer suite.DeleteAllDocuments()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func TestListNodes(t *testing.T) {
},
}

reportIds := suite.InsertInspecReports(reports)
reportIds, err := suite.InsertInspecReports(reports)
require.NoError(t, err)

defer suite.DeleteAllDocuments()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func TestListReports(t *testing.T) {
},
}

reportIds := suite.InsertInspecReports(reports)
reportIds, err := suite.InsertInspecReports(reports)
require.NoError(t, err)

defer suite.DeleteAllDocuments()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func TestReadNode(t *testing.T) {
Projects: []string{"project1", "project2"},
},
}
reportIds := suite.InsertInspecReports(reports)
reportIds, err := suite.InsertInspecReports(reports)
require.NoError(t, err)

defer suite.DeleteAllDocuments()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func TestReadReport(t *testing.T) {
Projects: []string{"project1", "project2"},
},
}
reportIds := suite.InsertInspecReports(reports)
reportIds, err := suite.InsertInspecReports(reports)
require.NoError(t, err)

defer suite.DeleteAllDocuments()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/golang/protobuf/ptypes"
_struct "github.com/golang/protobuf/ptypes/struct"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

iam_v2 "github.com/chef/automate/api/interservice/authz/v2"
automate_event "github.com/chef/automate/api/interservice/event"
Expand Down Expand Up @@ -1293,35 +1294,37 @@ func TestProjectUpdate(t *testing.T) {
for _, test := range cases {
t.Run(fmt.Sprintf("report match: %s", test.description),
func(t *testing.T) {
suite.InsertInspecReports([]*relaxting.ESInSpecReport{test.report})
suite.InsertInspecSummaries([]*relaxting.ESInSpecSummary{test.summary})
_, err := suite.InsertInspecReports([]*relaxting.ESInSpecReport{test.report})
require.NoError(t, err)
_, err = suite.InsertInspecSummaries([]*relaxting.ESInSpecSummary{test.summary})
require.NoError(t, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #464 I'm seeing failures from this test when the changes in that branch are seemingly unrelated. Previously this would fail silently.


// Send a project rules update event
esJobID, err := suite.ingesticESClient.UpdateReportProjectsTags(ctx, test.projects)
assert.Nil(t, err)
require.NoError(t, err)

suite.WaitForESJobToComplete(esJobID)

suite.RefreshComplianceReportIndex()

esJobID, err = suite.ingesticESClient.UpdateSummaryProjectsTags(ctx, test.projects)
assert.Nil(t, err)
require.NoError(t, err)

suite.WaitForESJobToComplete(esJobID)

suite.RefreshComplianceSummaryIndex()

reports, err := suite.GetAllReportsESInSpecReport()
assert.NoError(t, err)
assert.Equal(t, 1, len(reports))
require.NoError(t, err)
require.Equal(t, 1, len(reports))

updatedReport := reports[0]

assert.ElementsMatch(t, test.projectIDs, updatedReport.Projects)

summaries, err := suite.GetAllSummaryESInSpecSummary()
assert.NoError(t, err)
assert.Equal(t, 1, len(summaries))
require.NoError(t, err)
require.Equal(t, 1, len(summaries))

updatedSummary := summaries[0]

Expand Down
12 changes: 6 additions & 6 deletions components/compliance-service/integration_test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (s *Suite) WaitForESJobToComplete(esJobID string) {
}

// InsertInspecReports ingests a number of reports and at the end, refreshes the report index
func (s *Suite) InsertInspecReports(reports []*relaxting.ESInSpecReport) []string {
func (s *Suite) InsertInspecReports(reports []*relaxting.ESInSpecReport) ([]string, error) {
ids := make([]string, len(reports))

endTime := time.Now()
Expand All @@ -259,17 +259,17 @@ func (s *Suite) InsertInspecReports(reports []*relaxting.ESInSpecReport) []strin

err := s.ingesticESClient.InsertInspecReport(context.Background(), id, endTime, report)
if err != nil {
os.Exit(3)
return nil, err
}
}

s.RefreshComplianceReportIndex()

return ids
return ids, nil
}

// InsertInspecSummaries ingests a number of summaries and at the end, refreshes the summary index
func (s *Suite) InsertInspecSummaries(summaries []*relaxting.ESInSpecSummary) []string {
func (s *Suite) InsertInspecSummaries(summaries []*relaxting.ESInSpecSummary) ([]string, error) {
ids := make([]string, len(summaries))

endTime := time.Now()
Expand All @@ -280,13 +280,13 @@ func (s *Suite) InsertInspecSummaries(summaries []*relaxting.ESInSpecSummary) []

err := s.ingesticESClient.InsertInspecSummary(context.Background(), id, endTime, summary)
if err != nil {
os.Exit(3)
return nil, err
}
}

s.RefreshComplianceSummaryIndex()

return ids
return ids, nil
}

func (s *Suite) RefreshComplianceReportIndex() {
Expand Down