Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/util/allowed_tenants_test.go

47 lines
1.3 KiB

package util
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAllowedTenants_NoConfig(t *testing.T) {
a := NewAllowedTenants(nil, nil)
require.True(t, a.IsAllowed("all"))
require.True(t, a.IsAllowed("tenants"))
require.True(t, a.IsAllowed("allowed"))
}
func TestAllowedTenants_Enabled(t *testing.T) {
a := NewAllowedTenants([]string{"A", "B"}, nil)
require.True(t, a.IsAllowed("A"))
require.True(t, a.IsAllowed("B"))
require.False(t, a.IsAllowed("C"))
require.False(t, a.IsAllowed("D"))
}
func TestAllowedTenants_Disabled(t *testing.T) {
a := NewAllowedTenants(nil, []string{"A", "B"})
require.False(t, a.IsAllowed("A"))
require.False(t, a.IsAllowed("B"))
require.True(t, a.IsAllowed("C"))
require.True(t, a.IsAllowed("D"))
}
func TestAllowedTenants_Combination(t *testing.T) {
a := NewAllowedTenants([]string{"A", "B"}, []string{"B", "C"})
require.True(t, a.IsAllowed("A")) // enabled, and not disabled
require.False(t, a.IsAllowed("B")) // enabled, but also disabled
require.False(t, a.IsAllowed("C")) // disabled
require.False(t, a.IsAllowed("D")) // not enabled
}
func TestAllowedTenants_Nil(t *testing.T) {
var a *AllowedTenants
// All tenants are allowed when using nil as allowed tenants.
require.True(t, a.IsAllowed("A"))
require.True(t, a.IsAllowed("B"))
require.True(t, a.IsAllowed("C"))
}