Skip to content

Commit

Permalink
fix: refactor for review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidby-influx committed Dec 19, 2023
1 parent 2974e4e commit caa2b35
Show file tree
Hide file tree
Showing 47 changed files with 238 additions and 279 deletions.
12 changes: 6 additions & 6 deletions authorization/middleware_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,16 @@ func TestAuthorizationService_ReadAuthorization(t *testing.T) {

t.Run("find authorization by id", func(t *testing.T) {
_, err := s.FindAuthorizationByID(ctx, 10)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
t.Run("find authorization by token", func(t *testing.T) {
_, err := s.FindAuthorizationByToken(ctx, "10")
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})

t.Run("find authorizations", func(t *testing.T) {
as, _, err := s.FindAuthorizations(ctx, influxdb.AuthorizationFilter{})
influxdbtesting.ErrorsEqual(t, err, nil, false)
influxdbtesting.ErrorsEqual(t, err, nil)

if diff := cmp.Diff(as, tt.wants.authorizations, authorizationCmpOptions...); diff != "" {
t.Errorf("authorizations are different -got/+want\ndiff %s", diff)
Expand Down Expand Up @@ -323,12 +323,12 @@ func TestAuthorizationService_WriteAuthorization(t *testing.T) {

t.Run("update authorization", func(t *testing.T) {
_, err := s.UpdateAuthorization(ctx, 10, &influxdb.AuthorizationUpdate{Status: influxdb.Active.Ptr()})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})

t.Run("delete authorization", func(t *testing.T) {
err := s.DeleteAuthorization(ctx, 10)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})

})
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestAuthorizationService_CreateAuthorization(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.CreateAuthorization(ctx, &influxdb.Authorization{OrgID: 1, UserID: 1})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
12 changes: 6 additions & 6 deletions authorizer/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ func TestAuthorizationService_ReadAuthorization(t *testing.T) {

t.Run("find authorization by id", func(t *testing.T) {
_, err := s.FindAuthorizationByID(ctx, 10)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
t.Run("find authorization by token", func(t *testing.T) {
_, err := s.FindAuthorizationByToken(ctx, "10")
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})

t.Run("find authorizations", func(t *testing.T) {
as, _, err := s.FindAuthorizations(ctx, influxdb.AuthorizationFilter{})
influxdbtesting.ErrorsEqual(t, err, nil, false)
influxdbtesting.ErrorsEqual(t, err, nil)

if diff := cmp.Diff(as, tt.wants.authorizations, authorizationCmpOptions...); diff != "" {
t.Errorf("authorizations are different -got/+want\ndiff %s", diff)
Expand Down Expand Up @@ -304,12 +304,12 @@ func TestAuthorizationService_WriteAuthorization(t *testing.T) {

t.Run("update authorization", func(t *testing.T) {
_, err := s.UpdateAuthorization(ctx, 10, &influxdb.AuthorizationUpdate{Status: influxdb.Active.Ptr()})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})

t.Run("delete authorization", func(t *testing.T) {
err := s.DeleteAuthorization(ctx, 10)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})

})
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestAuthorizationService_CreateAuthorization(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.CreateAuthorization(ctx, &influxdb.Authorization{OrgID: 1, UserID: 1})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
12 changes: 6 additions & 6 deletions authorizer/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestBucketService_FindBucketByID(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

_, err := s.FindBucketByID(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestBucketService_FindBucket(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

_, err := s.FindBucket(ctx, influxdb.BucketFilter{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestBucketService_FindBuckets(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

buckets, _, err := s.FindBuckets(ctx, influxdb.BucketFilter{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

if diff := cmp.Diff(buckets, tt.wants.buckets, bucketCmpOptions...); diff != "" {
t.Errorf("buckets are different -got/+want\ndiff %s", diff)
Expand Down Expand Up @@ -437,7 +437,7 @@ func TestBucketService_UpdateBucket(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

_, err := s.UpdateBucket(ctx, tt.args.id, influxdb.BucketUpdate{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestBucketService_DeleteBucket(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.DeleteBucket(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestBucketService_CreateBucket(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

err := s.CreateBucket(ctx, &influxdb.Bucket{OrgID: tt.args.orgID})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
12 changes: 6 additions & 6 deletions authorizer/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestCheckService_FindCheckByID(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

_, err := s.FindCheckByID(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestCheckService_FindChecks(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

ts, _, err := s.FindChecks(ctx, influxdb.CheckFilter{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

if diff := cmp.Diff(ts, tt.wants.checks, checkCmpOptions...); diff != "" {
t.Errorf("checks are different -got/+want\ndiff %s", diff)
Expand Down Expand Up @@ -391,7 +391,7 @@ func TestCheckService_UpdateCheck(t *testing.T) {
}

_, err := s.UpdateCheck(ctx, tt.args.id, cc)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestCheckService_PatchCheck(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

_, err := s.PatchCheck(ctx, tt.args.id, influxdb.CheckUpdate{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -619,7 +619,7 @@ func TestCheckService_DeleteCheck(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.DeleteCheck(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -711,7 +711,7 @@ func TestCheckService_CreateCheck(t *testing.T) {
}

err := s.CreateCheck(ctx, cc, 3)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
22 changes: 11 additions & 11 deletions authorizer/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestDashboardService_FindDashboardByID(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

_, err := s.FindDashboardByID(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestDashboardService_FindDashboards(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

dashboards, _, err := s.FindDashboards(ctx, influxdb.DashboardFilter{}, influxdb.FindOptions{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestDashboardService_UpdateDashboard(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

_, err := s.UpdateDashboard(ctx, tt.args.id, influxdb.DashboardUpdate{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestDashboardService_DeleteDashboard(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.DeleteDashboard(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -539,7 +539,7 @@ func TestDashboardService_CreateDashboard(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

err := s.CreateDashboard(ctx, &influxdb.Dashboard{OrganizationID: tt.args.orgID})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -657,19 +657,19 @@ func TestDashboardService_WriteDashboardCell(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

err := s.AddDashboardCell(ctx, 1, &influxdb.Cell{}, influxdb.AddDashboardCellOptions{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

err = s.RemoveDashboardCell(ctx, 1, 2)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

_, err = s.UpdateDashboardCellView(ctx, 1, 2, influxdb.ViewUpdate{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

_, err = s.UpdateDashboardCell(ctx, 1, 2, influxdb.CellUpdate{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

err = s.ReplaceDashboardCells(ctx, 1, []*influxdb.Cell{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -763,7 +763,7 @@ func TestDashboardService_FindDashboardCellView(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

_, err := s.GetDashboardCellView(ctx, 1, 1)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
16 changes: 8 additions & 8 deletions authorizer/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestLabelService_FindLabelByID(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

_, err := s.FindLabelByID(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestLabelService_FindLabels(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

labels, err := s.FindLabels(ctx, influxdb.LabelFilter{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

if diff := cmp.Diff(labels, tt.wants.labels, labelCmpOptions...); diff != "" {
t.Errorf("labels are different -got/+want\ndiff %s", diff)
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestLabelService_UpdateLabel(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

_, err := s.UpdateLabel(ctx, tt.args.id, influxdb.LabelUpdate{})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -488,7 +488,7 @@ func TestLabelService_DeleteLabel(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.DeleteLabel(ctx, tt.args.id)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -592,7 +592,7 @@ func TestLabelService_CreateLabel(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))

err := s.CreateLabel(ctx, &influxdb.Label{Name: "name", OrgID: orgOneInfluxID})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -824,7 +824,7 @@ func TestLabelService_FindResourceLabels(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

labels, err := s.FindResourceLabels(ctx, tt.args.filter)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

if diff := cmp.Diff(labels, tt.wants.labels, labelCmpOptions...); diff != "" {
t.Errorf("labels are different -got/+want\ndiff %s", diff)
Expand Down Expand Up @@ -976,7 +976,7 @@ func TestLabelService_CreateLabelMapping(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.CreateLabelMapping(ctx, &tt.args.mapping)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Expand Down Expand Up @@ -1124,7 +1124,7 @@ func TestLabelService_DeleteLabelMapping(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, tt.args.permissions))

err := s.DeleteLabelMapping(ctx, &tt.args.mapping)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err, false)
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
}
Loading

0 comments on commit caa2b35

Please sign in to comment.