Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Higgins <[email protected]>
  • Loading branch information
phiggins committed Jun 4, 2019
1 parent 0eb5994 commit 962f84e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,12 @@ func TestListNodesFiltering(t *testing.T) {

for _, test := range cases {
t.Run(test.description, func(t *testing.T) {
suite.InsertInspecReports(test.reports)
_, err := suite.InsertInspecReports(test.reports)
require.NoError(t, err)
defer suite.DeleteAllDocuments()

response, err := server.ListNodes(ctx, &test.query)
assert.NoError(t, err)
require.NoError(t, err)
require.NotNil(t, response)

actualIds := make([]string, len(response.Nodes))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package integration_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -31,19 +30,12 @@ func TestListProfiles(t *testing.T) {
err := suite.ingestReport(reportFileName, func(r *compliance.Report) {
id := newUUID()

r.Environment = id
r.NodeName = id
r.Platform.Name = id
r.Profiles[0].Controls = r.Profiles[0].Controls[:1]
r.Profiles[0].Controls[0].Id = id
r.Profiles[0].Controls[0].Title = id
r.Profiles = r.Profiles[:1]
r.Profiles[0].Sha256 = id
r.Profiles[0].Title = id
r.Recipes = []string{id}
r.ReportUuid = id
r.Roles = []string{id}
r.EndTime = time.Now().UTC().Format(time.RFC3339)

reportIds[i] = id
})
Expand Down Expand Up @@ -83,19 +75,12 @@ func TestListProfiles(t *testing.T) {

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

suite.WaitForESJobToComplete(esJobID)

suite.RefreshComplianceReportIndex()

esJobID, err = suite.ingesticESClient.UpdateSummaryProjectsTags(everythingCtx, projectRules)
assert.Nil(t, err)

suite.WaitForESJobToComplete(esJobID)

suite.RefreshComplianceSummaryIndex()

profileIds := make([]string, len(reportIds))
for i := range reportIds {
profileId := reportIds[i]
Expand Down Expand Up @@ -163,7 +148,9 @@ func TestListProfiles(t *testing.T) {
t.Run(test.description, func(t *testing.T) {
ctx := contextWithProjects(test.allowedProjects)

response, err := server.ListProfiles(ctx, &reporting.Query{})
query := reporting.Query{Filters: []*reporting.ListFilter{{Type: "end_time", Values: []string{"2018-10-25T23:59:59Z"}}}}

response, err := server.ListProfiles(ctx, &query)

assert.NoError(t, err)
require.NotNil(t, response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,12 @@ func TestReportingListSuggestionsFiltering(t *testing.T) {

for _, test := range cases {
t.Run(test.description, func(t *testing.T) {
suite.InsertInspecSummaries(test.summaries)
_, err := suite.InsertInspecSummaries(test.summaries)
require.NoError(t, err)
defer suite.DeleteAllDocuments()

response, err := server.ListSuggestions(ctx, &test.request)
assert.NoError(t, err)
require.NoError(t, err)
require.NotNil(t, response)

actualTerms := make([]string, len(response.Suggestions))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,7 @@ func TestProjectUpdate(t *testing.T) {
_, err = suite.InsertInspecSummaries([]*relaxting.ESInSpecSummary{test.summary})
require.NoError(t, err)

defer suite.DeleteAllDocuments()
// Send a project rules update event
esJobID, err := suite.ingesticESClient.UpdateReportProjectsTags(ctx, test.projects)
require.NoError(t, err)
Expand Down Expand Up @@ -1329,8 +1330,6 @@ func TestProjectUpdate(t *testing.T) {
updatedSummary := summaries[0]

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

suite.DeleteAllDocuments()
})
}
}
Expand Down
35 changes: 2 additions & 33 deletions components/compliance-service/integration_test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,50 +363,19 @@ func (s *Suite) DeleteAllDocuments() {
// ES Query to match all documents
q := elastic.RawStringQuery("{\"match_all\":{}}")

// Make sure we clean them all!
indices, _ := s.elasticClient.IndexNames()

_, err := s.elasticClient.DeleteByQuery().
Index(indices...).
Type(s.types()...).
_, err := s.elasticClient.DeleteByQuery("_all").
Query(q).
IgnoreUnavailable(true).
Refresh("true").
WaitForCompletion(true).
Do(context.Background())

if err != nil {
fmt.Printf("Could not 'clean' ES documents from indices: '%v'\nError: %s", indices, err)
fmt.Printf("Could not 'clean' ES documents.\nError: %s", err)
os.Exit(3)
}
}

// types returns the list of ES types registered in the Ingest service code base
func (s *Suite) types() []string {
types := make([]string, len(mappings.AllMappings))

for i, esMap := range mappings.AllMappings {
types[i] = esMap.Type
}

return types
}

// Indices returns the list of ES indices registered in the Ingest service code base
func (s *Suite) Indices() []string {
indices := make([]string, len(mappings.AllMappings))

for i, esMap := range mappings.AllMappings {
if esMap.Timeseries {
indices[i] = esMap.IndexTimeseriesFmt(time.Now())
} else {
indices[i] = esMap.Index
}
}

return indices
}

type NotifierMock struct {
}

Expand Down

0 comments on commit 962f84e

Please sign in to comment.