Skip to content

Commit

Permalink
Test intersectiion
Browse files Browse the repository at this point in the history
  • Loading branch information
jeschkies committed Oct 7, 2024
1 parent 2da4270 commit 00a7e1f
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/logql/downstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
97 changes: 97 additions & 0 deletions pkg/util/validation/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package validation
import (
"testing"
"time"

"github.com/stretchr/testify/require"
)

// nolint:goconst
Expand Down Expand Up @@ -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 {

Check warning on line 236 in pkg/util/validation/limits_test.go

View workflow job for this annotation

GitHub Actions / check / golangciLint

unused-parameter: parameter 'tenantID' seems to be unused, consider removing or renaming it as _ (revive)
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)
})
}
}

0 comments on commit 00a7e1f

Please sign in to comment.