diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 97fc1c67b7e..aeb3b1e2595 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -444,7 +444,6 @@ lerna.json @grafana/frontend-ops /public/robots.txt @grafana/frontend-ops /public/sass/ @grafana/grafana-frontend-platform /public/test/ @grafana/grafana-frontend-platform -/public/testdata/ @grafana/grafana-frontend-platform /public/views/ @grafana/grafana-frontend-platform /public/app/features/explore/Logs/ @grafana/observability-logs diff --git a/pkg/api/plugin_resource_test.go b/pkg/api/plugin_resource_test.go index e44d34d4202..b7409befb4a 100644 --- a/pkg/api/plugin_resource_test.go +++ b/pkg/api/plugin_resource_test.go @@ -63,7 +63,7 @@ func TestCallResource(t *testing.T) { cfg.Azure = &azsettings.AzureSettings{} coreRegistry := coreplugin.ProvideCoreRegistry(nil, &cloudwatch.CloudWatchService{}, nil, nil, nil, nil, - nil, nil, nil, nil, testdatasource.ProvideService(cfg), nil, nil, nil, nil, nil, nil) + nil, nil, nil, nil, testdatasource.ProvideService(), nil, nil, nil, nil, nil, nil) pCfg, err := config.ProvideConfig(setting.ProvideProvider(cfg), cfg, featuremgmt.WithFeatures()) require.NoError(t, err) reg := registry.ProvideService() diff --git a/pkg/plugins/manager/manager_integration_test.go b/pkg/plugins/manager/manager_integration_test.go index d225a7ce562..08fc07a945f 100644 --- a/pkg/plugins/manager/manager_integration_test.go +++ b/pkg/plugins/manager/manager_integration_test.go @@ -103,7 +103,7 @@ func TestIntegrationPluginManager(t *testing.T) { otsdb := opentsdb.ProvideService(hcp) pr := prometheus.ProvideService(hcp, cfg, features, tracer) tmpo := tempo.ProvideService(hcp) - td := testdatasource.ProvideService(cfg) + td := testdatasource.ProvideService() pg := postgres.ProvideService(cfg) my := mysql.ProvideService(cfg, hcp) ms := mssql.ProvideService(cfg) diff --git a/pkg/services/store/service_test.go b/pkg/services/store/service_test.go index c5d34a0674e..206cf6c1e66 100644 --- a/pkg/services/store/service_test.go +++ b/pkg/services/store/service_test.go @@ -59,7 +59,6 @@ var ( Disk: &StorageLocalDiskConfig{ Path: publicRoot, Roots: []string{ - "/testdata/", "/img/icons/", "/img/bg/", "/gazetteer/", @@ -75,12 +74,12 @@ func TestListFiles(t *testing.T) { store := newStandardStorageService(db.InitTestDB(t), roots, func(orgId int64) []storageRuntime { return make([]storageRuntime, 0) }, allowAllAuthService, cfg, nil) - frame, err := store.List(context.Background(), dummyUser, "public/testdata") + frame, err := store.List(context.Background(), dummyUser, "public/maps") require.NoError(t, err) experimental.CheckGoldenJSONFrame(t, "testdata", "public_testdata.golden", frame.Frame, true) - file, err := store.Read(context.Background(), dummyUser, "public/testdata/js_libraries.csv") + file, err := store.Read(context.Background(), dummyUser, "public/maps/countries.geojson") require.NoError(t, err) require.NotNil(t, file) @@ -96,7 +95,7 @@ func TestListFilesWithoutPermissions(t *testing.T) { store := newStandardStorageService(db.InitTestDB(t), roots, func(orgId int64) []storageRuntime { return make([]storageRuntime, 0) }, denyAllAuthService, cfg, nil) - frame, err := store.List(context.Background(), dummyUser, "public/testdata") + frame, err := store.List(context.Background(), dummyUser, "public/maps") require.NoError(t, err) rowLen, err := frame.RowLen() require.NoError(t, err) diff --git a/pkg/services/store/testdata/public_testdata.golden.jsonc b/pkg/services/store/testdata/public_testdata.golden.jsonc index 69d35613452..bb87315815c 100644 --- a/pkg/services/store/testdata/public_testdata.golden.jsonc +++ b/pkg/services/store/testdata/public_testdata.golden.jsonc @@ -11,20 +11,15 @@ // } // } // Name: -// Dimensions: 3 Fields by 7 Rows -// +--------------------------+-------------------------+---------------+ -// | Name: name | Name: mediaType | Name: size | -// | Labels: | Labels: | Labels: | -// | Type: []string | Type: []string | Type: []int64 | -// +--------------------------+-------------------------+---------------+ -// | browser_marketshare.csv | text/csv; charset=utf-8 | 355 | -// | flight_info_by_state.csv | text/csv; charset=utf-8 | 681 | -// | gdp_per_capita.csv | text/csv; charset=utf-8 | 4116 | -// | js_libraries.csv | text/csv; charset=utf-8 | 179 | -// | ohlc_dogecoin.csv | text/csv; charset=utf-8 | 191804 | -// | population_by_state.csv | text/csv; charset=utf-8 | 138 | -// | weight_height.csv | text/csv; charset=utf-8 | 418121 | -// +--------------------------+-------------------------+---------------+ +// Dimensions: 3 Fields by 2 Rows +// +--------------------+----------------------+---------------+ +// | Name: name | Name: mediaType | Name: size | +// | Labels: | Labels: | Labels: | +// | Type: []string | Type: []string | Type: []int64 | +// +--------------------+----------------------+---------------+ +// | countries.geojson | application/geo+json | 255943 | +// | usa-states.geojson | application/geo+json | 89263 | +// +--------------------+----------------------+---------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -73,31 +68,16 @@ "data": { "values": [ [ - "browser_marketshare.csv", - "flight_info_by_state.csv", - "gdp_per_capita.csv", - "js_libraries.csv", - "ohlc_dogecoin.csv", - "population_by_state.csv", - "weight_height.csv" + "countries.geojson", + "usa-states.geojson" ], [ - "text/csv; charset=utf-8", - "text/csv; charset=utf-8", - "text/csv; charset=utf-8", - "text/csv; charset=utf-8", - "text/csv; charset=utf-8", - "text/csv; charset=utf-8", - "text/csv; charset=utf-8" + "application/geo+json", + "application/geo+json" ], [ - 355, - 681, - 4116, - 179, - 191804, - 138, - 418121 + 255943, + 89263 ] ] } diff --git a/pkg/tsdb/testdatasource/csv_data.go b/pkg/tsdb/testdatasource/csv_data.go index 6095275be56..6616e9d3042 100644 --- a/pkg/tsdb/testdatasource/csv_data.go +++ b/pkg/tsdb/testdatasource/csv_data.go @@ -2,11 +2,11 @@ package testdatasource import ( "context" + "embed" "encoding/csv" "errors" "fmt" "io" - "os" "path/filepath" "regexp" "strconv" @@ -92,6 +92,9 @@ func (s *Service) handleCsvFileScenario(ctx context.Context, req *backend.QueryD return resp, nil } +//go:embed data/*.csv +var embeddedCsvFiles embed.FS + func (s *Service) loadCsvFile(fileName string) (*data.Frame, error) { validFileName := regexp.MustCompile(`^\w+\.csv$`) @@ -100,11 +103,9 @@ func (s *Service) loadCsvFile(fileName string) (*data.Frame, error) { } csvFilepath := filepath.Clean(filepath.Join("/", fileName)) - filePath := filepath.Join(s.cfg.StaticRootPath, "testdata", csvFilepath) + filePath := filepath.Join("data", csvFilepath) - // Can ignore gosec G304 here, because we check the file pattern above - // nolint:gosec - fileReader, err := os.Open(filePath) + fileReader, err := embeddedCsvFiles.Open(filePath) if err != nil { return nil, fmt.Errorf("failed open file: %v", err) } diff --git a/public/testdata/browser_marketshare.csv b/pkg/tsdb/testdatasource/data/browser_marketshare.csv similarity index 100% rename from public/testdata/browser_marketshare.csv rename to pkg/tsdb/testdatasource/data/browser_marketshare.csv diff --git a/public/testdata/flight_info_by_state.csv b/pkg/tsdb/testdatasource/data/flight_info_by_state.csv similarity index 100% rename from public/testdata/flight_info_by_state.csv rename to pkg/tsdb/testdatasource/data/flight_info_by_state.csv diff --git a/public/testdata/gdp_per_capita.csv b/pkg/tsdb/testdatasource/data/gdp_per_capita.csv similarity index 100% rename from public/testdata/gdp_per_capita.csv rename to pkg/tsdb/testdatasource/data/gdp_per_capita.csv diff --git a/public/testdata/js_libraries.csv b/pkg/tsdb/testdatasource/data/js_libraries.csv similarity index 100% rename from public/testdata/js_libraries.csv rename to pkg/tsdb/testdatasource/data/js_libraries.csv diff --git a/public/testdata/ohlc_dogecoin.csv b/pkg/tsdb/testdatasource/data/ohlc_dogecoin.csv similarity index 100% rename from public/testdata/ohlc_dogecoin.csv rename to pkg/tsdb/testdatasource/data/ohlc_dogecoin.csv diff --git a/public/testdata/population_by_state.csv b/pkg/tsdb/testdatasource/data/population_by_state.csv similarity index 100% rename from public/testdata/population_by_state.csv rename to pkg/tsdb/testdatasource/data/population_by_state.csv diff --git a/public/testdata/weight_height.csv b/pkg/tsdb/testdatasource/data/weight_height.csv similarity index 100% rename from public/testdata/weight_height.csv rename to pkg/tsdb/testdatasource/data/weight_height.csv diff --git a/pkg/tsdb/testdatasource/testdata.go b/pkg/tsdb/testdatasource/testdata.go index 3622704a0a8..b544f76946a 100644 --- a/pkg/tsdb/testdatasource/testdata.go +++ b/pkg/tsdb/testdatasource/testdata.go @@ -10,11 +10,10 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/testdatasource/sims" ) -func ProvideService(cfg *setting.Cfg) *Service { +func ProvideService() *Service { s := &Service{ queryMux: datasource.NewQueryTypeMux(), scenarios: map[string]*Scenario{}, @@ -30,7 +29,6 @@ func ProvideService(cfg *setting.Cfg) *Service { data.NewField("Value", nil, make([]float64, 1)), ), logger: log.New("tsdb.testdata"), - cfg: cfg, } var err error @@ -46,7 +44,6 @@ func ProvideService(cfg *setting.Cfg) *Service { } type Service struct { - cfg *setting.Cfg logger log.Logger scenarios map[string]*Scenario frame *data.Frame