mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 13:09:22 -06:00
759cefd94c
* ExtSvcAccounts: FIX tests that accidently depended on enterprise * fix
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package manager
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
|
)
|
|
|
|
func Test_UsageStats(t *testing.T) {
|
|
acSvc := actest.FakeService{}
|
|
storeMock := newServiceAccountStoreFake()
|
|
svc := ServiceAccountsService{acSvc, storeMock, log.New("test"), log.New("background-test"), &SecretsCheckerFake{}, true, 5}
|
|
err := svc.DeleteServiceAccount(context.Background(), 1, 1)
|
|
require.NoError(t, err)
|
|
|
|
storeMock.ExpectedStats = &serviceaccounts.Stats{
|
|
ServiceAccounts: 1,
|
|
ServiceAccountsWithNoRole: 1,
|
|
Tokens: 1,
|
|
ForcedExpiryEnabled: false,
|
|
}
|
|
stats, err := svc.getUsageMetrics(context.Background())
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, stats, 5, stats)
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.count"].(int64))
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.role_none.count"].(int64))
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.tokens.count"].(int64))
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.secret_scan.enabled.count"].(int64))
|
|
assert.Equal(t, int64(0), stats["stats.serviceaccounts.forced_expiry_enabled.count"].(int64))
|
|
}
|