AccessControl: Remove unused error from GetResourcesMetadata (#43710)

* AccessControl: Remove unused error from GetResourcesMetadata

Co-authored-by: J Guerreiro <joao.guerreiro@grafana.com>
This commit is contained in:
Gabriel MABILLE
2022-01-05 17:24:14 +01:00
committed by GitHub
parent b4204628e4
commit 92c568e9f7
6 changed files with 8 additions and 24 deletions
+2 -2
View File
@@ -146,7 +146,7 @@ func addActionToMetadata(allMetadata map[string]Metadata, action, id string) map
}
// GetResourcesMetadata returns a map of accesscontrol metadata, listing for each resource, users available actions
func GetResourcesMetadata(ctx context.Context, permissions []*Permission, resource string, resourceIDs map[string]bool) (map[string]Metadata, error) {
func GetResourcesMetadata(ctx context.Context, permissions []*Permission, resource string, resourceIDs map[string]bool) map[string]Metadata {
allScope := GetResourceAllScope(resource)
allIDScope := GetResourceAllIDScope(resource)
@@ -171,5 +171,5 @@ func GetResourcesMetadata(ctx context.Context, permissions []*Permission, resour
}
}
return result, nil
return result
}
@@ -7,7 +7,6 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func setupTestEnv(b *testing.B, resourceCount, permissionPerResource int) ([]*Permission, map[string]bool) {
@@ -31,10 +30,8 @@ func benchGetMetadata(b *testing.B, resourceCount, permissionPerResource int) {
b.ResetTimer()
var metadata map[string]Metadata
var err error
for n := 0; n < b.N; n++ {
metadata, err = GetResourcesMetadata(context.Background(), permissions, "resources", ids)
require.NoError(b, err)
metadata = GetResourcesMetadata(context.Background(), permissions, "resources", ids)
assert.Len(b, metadata, resourceCount)
for _, resourceMetadata := range metadata {
assert.Len(b, resourceMetadata, permissionPerResource)
@@ -53,7 +50,7 @@ func BenchmarkGetResourcesMetadata_10_1000000(b *testing.B) {
benchGetMetadata(b, 10, 1000000)
} // ~3.89s/op
// Lots of resources (worst case)
// Lots of resources
func BenchmarkGetResourcesMetadata_1000_10(b *testing.B) { benchGetMetadata(b, 1000, 10) } // ~0,0023s/op
func BenchmarkGetResourcesMetadata_10000_10(b *testing.B) { benchGetMetadata(b, 10000, 10) } // ~0.021s/op
func BenchmarkGetResourcesMetadata_100000_10(b *testing.B) { benchGetMetadata(b, 100000, 10) } // ~0.22s/op
@@ -5,7 +5,6 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetResourcesMetadata(t *testing.T) {
@@ -95,9 +94,7 @@ func TestGetResourcesMetadata(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
metadata, err := GetResourcesMetadata(context.Background(), tt.permissions, tt.resource, tt.resourcesIDs)
require.NoError(t, err)
metadata := GetResourcesMetadata(context.Background(), tt.permissions, tt.resource, tt.resourcesIDs)
assert.EqualValues(t, tt.expected, metadata)
})
}