Refactor secrets service test helper

This commit is contained in:
Tania B
2021-10-25 16:31:00 +03:00
parent b83f8f7e3c
commit 57eec16a10
2 changed files with 3 additions and 14 deletions
+1 -11
View File
@@ -6,23 +6,13 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/services/encryption/ossencryption"
"github.com/grafana/grafana/pkg/services/secrets"
"github.com/grafana/grafana/pkg/services/secrets/database"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/require"
"gopkg.in/ini.v1"
)
func SetupTestService(tb testing.TB, db *sqlstore.SQLStore) *SecretsService {
if db == nil {
return setupTestService(tb, fakes.NewFakeSecretsStore())
}
return setupTestService(tb, database.ProvideSecretsStore(db))
}
func setupTestService(tb testing.TB, store secrets.Store) *SecretsService {
func SetupTestService(tb testing.TB, store secrets.Store) *SecretsService {
tb.Helper()
defaultKey := "SdlklWklckeLS"
if len(setting.SecretKey) > 0 {
+2 -3
View File
@@ -4,18 +4,17 @@ import (
"context"
"testing"
"github.com/grafana/grafana/pkg/services/secrets"
"github.com/grafana/grafana/pkg/services/secrets/database"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/secrets"
)
func TestSecrets_EnvelopeEncryption(t *testing.T) {
store := database.ProvideSecretsStore(sqlstore.InitTestDB(t))
svc := setupTestService(t, store)
svc := SetupTestService(t, store)
ctx := context.Background()
t.Run("encrypting with no entity_id should create DEK", func(t *testing.T) {