diff --git a/pkg/logql/downstream_test.go b/pkg/logql/downstream_test.go index 0dfb38d034e67..7be0fbb5fbc52 100644 --- a/pkg/logql/downstream_test.go +++ b/pkg/logql/downstream_test.go @@ -726,7 +726,7 @@ func TestRangeMappingEquivalence(t *testing.T) { rangeQry := downstreamEngine.Query(ctx, ParamsWithExpressionOverride{Params: params, ExpressionOverride: rangeExpr}) rangeRes, err := rangeQry.Exec(ctx) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, res.Data, rangeRes.Data) }) diff --git a/pkg/util/validation/limits_test.go b/pkg/util/validation/limits_test.go index 896b11ee7d3a4..77bac1439b91d 100644 --- a/pkg/util/validation/limits_test.go +++ b/pkg/util/validation/limits_test.go @@ -3,6 +3,8 @@ package validation import ( "testing" "time" + + "github.com/stretchr/testify/require" ) // nolint:goconst @@ -220,3 +222,98 @@ func TestMaxDurationOrZeroPerTenant(t *testing.T) { }) } } + +func TestIntersectionPerTenant(t *testing.T) { + tests := []struct { + name string + tenantIDs []string + f func(string) []string + expected []string + }{ + { + name: "no tenants", + tenantIDs: []string{}, + f: func(tenantID string) []string { + return nil + }, + expected: []string{}, + }, + { + name: "single tenant with features", + tenantIDs: []string{"tenant1"}, + f: func(tenantID string) []string { + if tenantID == "tenant1" { + return []string{"featureA", "featureB", "featureC"} + } + return nil + }, + expected: []string{"featureA", "featureB", "featureC"}, + }, + { + name: "multiple tenants with common features", + tenantIDs: []string{"tenant1", "tenant2"}, + f: func(tenantID string) []string { + if tenantID == "tenant1" { + return []string{"featureA", "featureB", "featureC"} + } + if tenantID == "tenant2" { + return []string{"featureB", "featureC", "featureD"} + } + return nil + }, + expected: []string{"featureB", "featureC"}, + }, + { + name: "multiple tenants with no common features", + tenantIDs: []string{"tenant1", "tenant2"}, + f: func(tenantID string) []string { + if tenantID == "tenant1" { + return []string{"featureA"} + } + if tenantID == "tenant2" { + return []string{"featureB"} + } + return nil + }, + expected: []string{}, + }, + { + name: "multiple tenants with overlapping features", + tenantIDs: []string{"tenant1", "tenant2", "tenant3"}, + f: func(tenantID string) []string { + if tenantID == "tenant1" { + return []string{"featureA", "featureB"} + } + if tenantID == "tenant2" { + return []string{"featureB", "featureC"} + } + if tenantID == "tenant3" { + return []string{"featureB", "featureD"} + } + return nil + }, + expected: []string{"featureB"}, + }, + { + name: "tenant with empty feature set", + tenantIDs: []string{"tenant1", "tenant2"}, + f: func(tenantID string) []string { + if tenantID == "tenant1" { + return []string{"featureA", "featureB"} + } + if tenantID == "tenant2" { + return []string{} + } + return nil + }, + expected: []string{}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := IntersectionPerTenant(tt.tenantIDs, tt.f) + require.ElementsMatch(t, actual, tt.expected) + }) + } +}