diff --git a/internal/service/policy/policydata/refresher_test.go b/internal/service/policy/policydata/refresher_test.go index b2a0f7b06e8747d6dd6962416f694296e26d131a..bdfd0ace6f473b72b045bbef4c39edad5c3474f9 100644 --- a/internal/service/policy/policydata/refresher_test.go +++ b/internal/service/policy/policydata/refresher_test.go @@ -34,7 +34,7 @@ func Test_Execute(t *testing.T) { // test input name string statusCode int - policy storage.Policy + policy *storage.Policy storage policydata.Storage // expected result logCnt int @@ -42,7 +42,7 @@ func Test_Execute(t *testing.T) { }{ { name: "invalid data configuration", - policy: storage.Policy{DataConfig: "<invalid data configuration>"}, + policy: &storage.Policy{DataConfig: "<invalid data configuration>"}, storage: &policydatafakes.FakeStorage{ UpdateNextRefreshTimeStub: func(ctx context.Context, policy *storage.Policy, t time.Time) error { return nil @@ -53,7 +53,7 @@ func Test_Execute(t *testing.T) { }, { name: "data configuration is missing required fields", - policy: storage.Policy{DataConfig: `{"url": "https://example.com"}`}, + policy: &storage.Policy{DataConfig: `{"url": "https://example.com"}`}, storage: &policydatafakes.FakeStorage{ UpdateNextRefreshTimeStub: func(ctx context.Context, policy *storage.Policy, t time.Time) error { return nil @@ -64,7 +64,7 @@ func Test_Execute(t *testing.T) { }, { name: "error making an http request", - policy: storage.Policy{DataConfig: `{"url": "htt//example.com", "method": "GET", "period": "1h"}`}, + policy: &storage.Policy{DataConfig: `{"url": "htt//example.com", "method": "GET", "period": "1h"}`}, storage: &policydatafakes.FakeStorage{ UpdateNextRefreshTimeStub: func(ctx context.Context, policy *storage.Policy, t time.Time) error { return nil @@ -76,7 +76,7 @@ func Test_Execute(t *testing.T) { { name: "unexpected response code", statusCode: 500, - policy: storage.Policy{DataConfig: `{"url": "https://example.com", "method": "GET", "period": "1h"}`}, + policy: &storage.Policy{DataConfig: `{"url": "https://example.com", "method": "GET", "period": "1h"}`}, storage: &policydatafakes.FakeStorage{ UpdateNextRefreshTimeStub: func(ctx context.Context, policy *storage.Policy, t time.Time) error { return nil @@ -87,7 +87,7 @@ func Test_Execute(t *testing.T) { }, { name: "error updating data after successful refresh request", - policy: storage.Policy{DataConfig: `{"url": "https://example.com", "method": "GET", "period": "1h"}`}, + policy: &storage.Policy{DataConfig: `{"url": "https://example.com", "method": "GET", "period": "1h"}`}, storage: &policydatafakes.FakeStorage{ UpdateNextRefreshTimeStub: func(ctx context.Context, policy *storage.Policy, t time.Time) error { return errors.New("storage error") @@ -98,7 +98,7 @@ func Test_Execute(t *testing.T) { }, { name: "data refresh is successfully executed", - policy: storage.Policy{DataConfig: `{"url": "https://example.com", "method": "GET", "period": "1h"}`}, + policy: &storage.Policy{DataConfig: `{"url": "https://example.com", "method": "GET", "period": "1h"}`}, storage: &policydatafakes.FakeStorage{ UpdateNextRefreshTimeStub: func(ctx context.Context, policy *storage.Policy, t time.Time) error { return nil @@ -121,7 +121,7 @@ func Test_Execute(t *testing.T) { }) } refresher := policydata.NewRefresher(test.storage, time.Duration(0), httpClient, logger) - refresher.Execute(context.Background(), (*storage.Policy)(&test.policy)) + refresher.Execute(context.Background(), test.policy) assert.Equal(t, test.logCnt, observedLogs.Len()) if observedLogs.Len() > 0 { diff --git a/internal/storage/storage.go b/internal/storage/storage.go index f30c7a67aa86d7cd71d5387a41cd4de9bbe2e3b2..e2941139380e272047cfb8d7812eee4abc4a45e3 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -165,9 +165,9 @@ func (s *Storage) GetRefreshPolicies(ctx context.Context) ([]*Policy, error) { // PostponeRefresh adds a refreshPostponePeriod Duration to each policy's // nextDataRefreshTimeField in order to prevent concurrent data refresh func (s *Storage) PostponeRefresh(ctx context.Context, policies []*Policy) error { - var ids []*primitive.ObjectID + var ids []primitive.ObjectID for _, p := range policies { - ids = append(ids, (*primitive.ObjectID)(&p.ID)) + ids = append(ids, p.ID) } filter := bson.M{"_id": bson.M{"$in": ids}}