mirror of https://github.com/grafana/grafana.git
PoC: replace using testing.Short in storage/unified package with integration test skip method (#107887)
* PoC: check if testing.Short is called from integration tests only. * Rename helper function. * Fix logic. * Remove skipping of integration tests from non-integration tests. * Remove skipping of integration tests from non-integration tests. * Fix import.
This commit is contained in:
parent
5108225785
commit
9d2eadcfd2
|
|
@ -40,6 +40,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/storage/unified/resourcepb"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/sql"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
|
||||
"github.com/grafana/grafana/pkg/tests"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
)
|
||||
|
||||
|
|
@ -134,9 +135,7 @@ func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Inte
|
|||
_, err = server.IsHealthy(ctx, &resourcepb.HealthCheckRequest{})
|
||||
require.NoError(t, err)
|
||||
case StorageTypeUnified:
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
tests.SkipIntegrationTestInShortMode(t)
|
||||
dbstore := infraDB.InitTestDB(t)
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
|
|
@ -190,7 +189,7 @@ func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Inte
|
|||
return ctx, store, destroyFunc, nil
|
||||
}
|
||||
|
||||
func TestWatch(t *testing.T) {
|
||||
func TestIntegrationWatch(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t, withStorageType(s))
|
||||
|
|
|
|||
|
|
@ -13,10 +13,6 @@ import (
|
|||
)
|
||||
|
||||
func TestBleveSearchBackend(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
// Run the search backend test suite
|
||||
unitest.RunSearchBackendTest(t, func(ctx context.Context) resource.SearchBackend {
|
||||
tempDir := t.TempDir()
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/storage/unified/sql"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
|
||||
test "github.com/grafana/grafana/pkg/storage/unified/testing"
|
||||
"github.com/grafana/grafana/pkg/tests"
|
||||
)
|
||||
|
||||
func newTestBackend(b testing.TB) resource.StorageBackend {
|
||||
|
|
@ -38,9 +39,7 @@ func newTestBackend(b testing.TB) resource.StorageBackend {
|
|||
}
|
||||
|
||||
func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test in short mode")
|
||||
}
|
||||
tests.SkipIntegrationTestInShortMode(t)
|
||||
opts := test.DefaultBenchmarkOptions()
|
||||
if db.IsTestDbSQLite() {
|
||||
opts.Concurrency = 1 // to avoid SQLite database is locked error
|
||||
|
|
@ -49,9 +48,7 @@ func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntegrationBenchmarkResourceServer(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test in short mode")
|
||||
}
|
||||
tests.SkipIntegrationTestInShortMode(t)
|
||||
|
||||
ctx := context.Background()
|
||||
opts := &test.BenchmarkOptions{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/storage/unified/sql"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
|
||||
unitest "github.com/grafana/grafana/pkg/storage/unified/testing"
|
||||
"github.com/grafana/grafana/pkg/tests"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
"github.com/grafana/grafana/pkg/util/testutil"
|
||||
)
|
||||
|
|
@ -95,9 +96,7 @@ func TestIntegrationSQLStorageBackend(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntegrationSearchAndStorage(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test in short mode")
|
||||
}
|
||||
tests.SkipIntegrationTestInShortMode(t)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
|
|||
|
|
@ -43,10 +43,6 @@ func GenerateRandomKVPrefix() string {
|
|||
|
||||
// RunKVTest runs the KV test suite
|
||||
func RunKVTest(t *testing.T, newKV NewKVFunc, opts *KVTestOptions) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
if opts == nil {
|
||||
opts = &KVTestOptions{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,6 @@ type NewSearchBackendFunc func(ctx context.Context) resource.SearchBackend
|
|||
|
||||
// RunSearchBackendTest runs the search backend test suite
|
||||
func RunSearchBackendTest(t *testing.T, newBackend NewSearchBackendFunc, opts *TestOptions) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
if opts == nil {
|
||||
opts = &TestOptions{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@ import (
|
|||
"crypto/tls"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
goapi "github.com/grafana/grafana-openapi-client-go/client"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
|
||||
|
|
@ -19,9 +22,18 @@ import (
|
|||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func SkipIntegrationTestInShortMode(t testing.TB) {
|
||||
t.Helper()
|
||||
if !strings.HasPrefix(t.Name(), "TestIntegration") {
|
||||
t.Fatal("test is not an integration test")
|
||||
}
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test in short mode")
|
||||
}
|
||||
}
|
||||
|
||||
func CreateUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
|
||||
t.Helper()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue