grafana/pkg/services/serviceaccounts/manager/service_test.go
Eric Leijonmarck 8677552dda
Service accounts: rename feature toggle (#48037)
* refactor: renaming service-accounts to serviceAccounts

* refactor: renaming service-accounts to serviceAccounts in docs

* tests
2022-04-21 10:41:37 +01:00

37 lines
1.2 KiB
Go

package manager
import (
"context"
"testing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/serviceaccounts/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestProvideServiceAccount_DeleteServiceAccount(t *testing.T) {
t.Run("feature toggle present, should call store function", func(t *testing.T) {
storeMock := &tests.ServiceAccountsStoreMock{Calls: tests.Calls{}}
svc := ServiceAccountsService{
features: featuremgmt.WithFeatures("serviceAccounts", true),
store: storeMock}
err := svc.DeleteServiceAccount(context.Background(), 1, 1)
require.NoError(t, err)
assert.Len(t, storeMock.Calls.DeleteServiceAccount, 1)
})
t.Run("no feature toggle present, should not call store function", func(t *testing.T) {
svcMock := &tests.ServiceAccountsStoreMock{Calls: tests.Calls{}}
svc := ServiceAccountsService{
features: featuremgmt.WithFeatures("serviceAccounts", false),
store: svcMock,
log: log.New("serviceaccounts-manager-test"),
}
err := svc.DeleteServiceAccount(context.Background(), 1, 1)
require.NoError(t, err)
assert.Len(t, svcMock.Calls.DeleteServiceAccount, 0)
})
}