Refactor secrets service test helper
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user