Skip to content

Commit

Permalink
test: fix inconsistent test due to unordered slices comparison (#355)
Browse files Browse the repository at this point in the history
* test: fix inconsistent test due to map comparison

* chore: use cmp diff to sort the slices

* fix: sort related permissions
  • Loading branch information
rahmatrhd authored Feb 1, 2023
1 parent 134681e commit 185ee90
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plugins/providers/bigquery/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"sort"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -317,6 +318,7 @@ func (p *Provider) GetActivities(ctx context.Context, pd domain.Provider, filter
}
}
a.RelatedPermissions = slices.UniqueStringSlice(a.RelatedPermissions)
sort.Strings(a.RelatedPermissions)

activities = append(activities, a)
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/providers/bigquery/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"cloud.google.com/go/logging"
"github.com/google/go-cmp/cmp"
"github.com/odpf/guardian/core/provider"
"github.com/odpf/guardian/domain"
"github.com/odpf/guardian/plugins/providers/bigquery"
Expand Down Expand Up @@ -1148,7 +1149,7 @@ func (s *BigQueryProviderTestSuite) TestGetActivities_Success() {
s.mockCloudLoggingClient.AssertExpectations(s.T())
s.mockBigQueryClient.AssertExpectations(s.T())
s.NoError(err)
s.Equal(expectedActivities, actualActivities)
s.Empty(cmp.Diff(expectedActivities, actualActivities))
})

s.Run("should return error if there is an error on initializing logging client", func() {
Expand Down

0 comments on commit 185ee90

Please sign in to comment.