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:
Peter Štibraný 2025-07-09 17:32:10 +02:00 committed by GitHub
parent 5108225785
commit 9d2eadcfd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 21 additions and 26 deletions

View File

@ -40,6 +40,7 @@ import (
"github.com/grafana/grafana/pkg/storage/unified/resourcepb" "github.com/grafana/grafana/pkg/storage/unified/resourcepb"
"github.com/grafana/grafana/pkg/storage/unified/sql" "github.com/grafana/grafana/pkg/storage/unified/sql"
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl" "github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
"github.com/grafana/grafana/pkg/tests"
"github.com/grafana/grafana/pkg/tests/testsuite" "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{}) _, err = server.IsHealthy(ctx, &resourcepb.HealthCheckRequest{})
require.NoError(t, err) require.NoError(t, err)
case StorageTypeUnified: case StorageTypeUnified:
if testing.Short() { tests.SkipIntegrationTestInShortMode(t)
t.Skip("skipping integration test")
}
dbstore := infraDB.InitTestDB(t) dbstore := infraDB.InitTestDB(t)
cfg := setting.NewCfg() cfg := setting.NewCfg()
@ -190,7 +189,7 @@ func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Inte
return ctx, store, destroyFunc, nil return ctx, store, destroyFunc, nil
} }
func TestWatch(t *testing.T) { func TestIntegrationWatch(t *testing.T) {
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} { for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
t.Run(string(s), func(t *testing.T) { t.Run(string(s), func(t *testing.T) {
ctx, store, destroyFunc, err := testSetup(t, withStorageType(s)) ctx, store, destroyFunc, err := testSetup(t, withStorageType(s))

View File

@ -13,10 +13,6 @@ import (
) )
func TestBleveSearchBackend(t *testing.T) { func TestBleveSearchBackend(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
// Run the search backend test suite // Run the search backend test suite
unitest.RunSearchBackendTest(t, func(ctx context.Context) resource.SearchBackend { unitest.RunSearchBackendTest(t, func(ctx context.Context) resource.SearchBackend {
tempDir := t.TempDir() tempDir := t.TempDir()

View File

@ -17,6 +17,7 @@ import (
"github.com/grafana/grafana/pkg/storage/unified/sql" "github.com/grafana/grafana/pkg/storage/unified/sql"
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl" "github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
test "github.com/grafana/grafana/pkg/storage/unified/testing" test "github.com/grafana/grafana/pkg/storage/unified/testing"
"github.com/grafana/grafana/pkg/tests"
) )
func newTestBackend(b testing.TB) resource.StorageBackend { func newTestBackend(b testing.TB) resource.StorageBackend {
@ -38,9 +39,7 @@ func newTestBackend(b testing.TB) resource.StorageBackend {
} }
func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) { func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) {
if testing.Short() { tests.SkipIntegrationTestInShortMode(t)
t.Skip("skipping integration test in short mode")
}
opts := test.DefaultBenchmarkOptions() opts := test.DefaultBenchmarkOptions()
if db.IsTestDbSQLite() { if db.IsTestDbSQLite() {
opts.Concurrency = 1 // to avoid SQLite database is locked error opts.Concurrency = 1 // to avoid SQLite database is locked error
@ -49,9 +48,7 @@ func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) {
} }
func TestIntegrationBenchmarkResourceServer(t *testing.T) { func TestIntegrationBenchmarkResourceServer(t *testing.T) {
if testing.Short() { tests.SkipIntegrationTestInShortMode(t)
t.Skip("skipping integration test in short mode")
}
ctx := context.Background() ctx := context.Background()
opts := &test.BenchmarkOptions{ opts := &test.BenchmarkOptions{

View File

@ -26,6 +26,7 @@ import (
"github.com/grafana/grafana/pkg/storage/unified/sql" "github.com/grafana/grafana/pkg/storage/unified/sql"
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl" "github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
unitest "github.com/grafana/grafana/pkg/storage/unified/testing" 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/tests/testsuite"
"github.com/grafana/grafana/pkg/util/testutil" "github.com/grafana/grafana/pkg/util/testutil"
) )
@ -95,9 +96,7 @@ func TestIntegrationSQLStorageBackend(t *testing.T) {
} }
func TestIntegrationSearchAndStorage(t *testing.T) { func TestIntegrationSearchAndStorage(t *testing.T) {
if testing.Short() { tests.SkipIntegrationTestInShortMode(t)
t.Skip("skipping integration test in short mode")
}
ctx := context.Background() ctx := context.Background()

View File

@ -43,10 +43,6 @@ func GenerateRandomKVPrefix() string {
// RunKVTest runs the KV test suite // RunKVTest runs the KV test suite
func RunKVTest(t *testing.T, newKV NewKVFunc, opts *KVTestOptions) { func RunKVTest(t *testing.T, newKV NewKVFunc, opts *KVTestOptions) {
if testing.Short() {
t.Skip("skipping integration test")
}
if opts == nil { if opts == nil {
opts = &KVTestOptions{} opts = &KVTestOptions{}
} }

View File

@ -24,10 +24,6 @@ type NewSearchBackendFunc func(ctx context.Context) resource.SearchBackend
// RunSearchBackendTest runs the search backend test suite // RunSearchBackendTest runs the search backend test suite
func RunSearchBackendTest(t *testing.T, newBackend NewSearchBackendFunc, opts *TestOptions) { func RunSearchBackendTest(t *testing.T, newBackend NewSearchBackendFunc, opts *TestOptions) {
if testing.Short() {
t.Skip("skipping integration test")
}
if opts == nil { if opts == nil {
opts = &TestOptions{} opts = &TestOptions{}
} }

View File

@ -5,10 +5,13 @@ import (
"crypto/tls" "crypto/tls"
"net/url" "net/url"
"os" "os"
"strings"
"testing" "testing"
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
goapi "github.com/grafana/grafana-openapi-client-go/client" 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/db"
"github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" "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"
"github.com/grafana/grafana/pkg/services/user/userimpl" "github.com/grafana/grafana/pkg/services/user/userimpl"
"github.com/grafana/grafana/pkg/setting" "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 { func CreateUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
t.Helper() t.Helper()