2022-08-23 07:24:55 -05:00
|
|
|
package manager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-01-30 02:34:18 -06:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
|
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
2022-08-23 07:24:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_UsageStats(t *testing.T) {
|
2022-12-13 07:56:10 -06:00
|
|
|
storeMock := newServiceAccountStoreFake()
|
|
|
|
svc := ServiceAccountsService{storeMock, log.New("test"), log.New("background-test"), &SecretsCheckerFake{}, true, 5}
|
2022-08-23 07:24:55 -05:00
|
|
|
err := svc.DeleteServiceAccount(context.Background(), 1, 1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-13 07:56:10 -06:00
|
|
|
storeMock.ExpectedStats = &serviceaccounts.Stats{
|
2023-08-16 03:56:47 -05:00
|
|
|
ServiceAccounts: 1,
|
|
|
|
ServiceAccountsWithNoRole: 1,
|
|
|
|
Tokens: 1,
|
|
|
|
ForcedExpiryEnabled: false,
|
2022-12-13 07:56:10 -06:00
|
|
|
}
|
2022-08-23 07:24:55 -05:00
|
|
|
stats, err := svc.getUsageMetrics(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-08-16 03:56:47 -05:00
|
|
|
assert.Len(t, stats, 5, stats)
|
2022-08-23 07:24:55 -05:00
|
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.count"].(int64))
|
2023-08-16 03:56:47 -05:00
|
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.role_none.count"].(int64))
|
2022-08-23 07:24:55 -05:00
|
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.tokens.count"].(int64))
|
2022-11-07 04:46:19 -06:00
|
|
|
assert.Equal(t, int64(1), stats["stats.serviceaccounts.secret_scan.enabled.count"].(int64))
|
2023-03-16 10:36:31 -05:00
|
|
|
assert.Equal(t, int64(0), stats["stats.serviceaccounts.forced_expiry_enabled.count"].(int64))
|
2022-08-23 07:24:55 -05:00
|
|
|
}
|