Chore: Embed CSV files with the test data source (#71435)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
+15
-35
@@ -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
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
Browser,Market share
|
||||
IE,17.5
|
||||
Chrome,50.27
|
||||
Firefox,16.89
|
||||
Safari,9.94
|
||||
Opera,1.7
|
||||
Android,1.32
|
||||
360 Safe Browser,0.41
|
||||
Maxthon,0.25
|
||||
Sony PS3,0.04
|
||||
Yandex Browser,0.36
|
||||
Silk,0.23
|
||||
Sogou Explorer,0.23
|
||||
Mozilla,0.03
|
||||
Chromium,0.13
|
||||
AOL,0
|
||||
QQ Browser,0.14
|
||||
SeaMonkey,0.02
|
||||
RockMelt,0
|
||||
BlackBerry,0.01
|
||||
Iron,0.01
|
||||
Pale Moon,0.03
|
||||
Flock,0
|
||||
TheWorld,0.02
|
||||
UC Browser,0.08
|
||||
Other,0.38
|
||||
|
@@ -0,0 +1,18 @@
|
||||
State, Lat,Lng,DestLocation,Count,Price
|
||||
Alaska, 61.3850,-152.2683,bdg,5,500
|
||||
Alabama, 32.7990,-86.8073,djf,3,300
|
||||
Arizona, 33.7712,-111.3877,9w0,10,150
|
||||
California, 36.1700,-119.7462,9q6,12,250
|
||||
Colorado, 39.0646,-105.3272,9wv,1,600
|
||||
Florida, 27.8333,-81.7170,dhv,5,500
|
||||
Iowa, 42.0046,-93.2140,9zm,7,700
|
||||
Illinois, 40.3363,-89.0022,dp0,1,400
|
||||
Indiana, 39.8647,-86.2604,dp4,5,540
|
||||
Kentucky, 37.6690,-84.6514,dne,6,630
|
||||
Massachusetts, 42.2373,-71.5314,drt,11,460
|
||||
Michigan, 43.3504,-84.5603,dpe,2,250
|
||||
North Carolina, 35.6411,-79.8431,dnr,5,500
|
||||
New Jersey, 40.3140,-74.5089,dr5,12,400
|
||||
New Mexico, 34.8375,-106.2371,9wh,15,800
|
||||
Ohio, 40.3736,-82.7755,dpj,9,930
|
||||
Oregon, 44.5672,-122.1269,9rc,3,360
|
||||
|
@@ -0,0 +1,230 @@
|
||||
Country,GDP Per Capita
|
||||
"Qatar",103900
|
||||
"Liechtenstein",89400
|
||||
"Bermuda",86000
|
||||
"Macau",82400
|
||||
"Luxembourg",81100
|
||||
"Monaco",70700
|
||||
"Singapore",61400
|
||||
"Jersey",57000
|
||||
"Norway",55900
|
||||
"Falkland Islands (Islas Malvinas)",55400
|
||||
"Brunei",55300
|
||||
"Isle of Man",53800
|
||||
"Hong Kong",52300
|
||||
"United States",50700
|
||||
"United Arab Emirates",49800
|
||||
"Switzerland",46200
|
||||
"Guernsey",44600
|
||||
"Cayman Islands",43800
|
||||
"Canada",43400
|
||||
"Australia",43300
|
||||
"Austria",43100
|
||||
"Gibraltar",43000
|
||||
"Netherlands",42900
|
||||
"Ireland",42600
|
||||
"British Virgin Islands",42300
|
||||
"Sweden",41900
|
||||
"Kuwait",40500
|
||||
"Iceland",39900
|
||||
"Germany",39700
|
||||
"Taiwan",39400
|
||||
"Belgium",38500
|
||||
"Denmark",38300
|
||||
"New Caledonia",37700
|
||||
"United Kingdom",37500
|
||||
"Greenland",37400
|
||||
"Andorra",37200
|
||||
"Finland",37000
|
||||
"Japan",36900
|
||||
"San Marino",36200
|
||||
"France",36100
|
||||
"European Union",35100
|
||||
"Saint Pierre and Miquelon",34900
|
||||
"Israel",32800
|
||||
"Korea, South",32800
|
||||
"Bahamas, The",31900
|
||||
"Saudi Arabia",31800
|
||||
"Spain",31100
|
||||
"Italy",30600
|
||||
"Faroe Islands",30500
|
||||
"New Zealand",30200
|
||||
"Oman",29600
|
||||
"Bahrain",29200
|
||||
"Turks and Caicos Islands",29100
|
||||
"Slovenia",28700
|
||||
"Guam",28700
|
||||
"Czech Republic",27600
|
||||
"Malta",27500
|
||||
"Cyprus",27500
|
||||
"Equatorial Guinea",26400
|
||||
"Barbados",25800
|
||||
"Seychelles",25600
|
||||
"Aruba",25300
|
||||
"Greece",24900
|
||||
"Slovakia",24600
|
||||
"Portugal",23800
|
||||
"Estonia",22100
|
||||
"French Polynesia",22000
|
||||
"Lithuania",22000
|
||||
"Poland",20900
|
||||
"Trinidad and Tobago",20400
|
||||
"Hungary",20000
|
||||
"Chile",18700
|
||||
"Latvia",18600
|
||||
"Argentina",18400
|
||||
"Antigua and Barbuda",18300
|
||||
"Croatia",18100
|
||||
"Russia",18000
|
||||
"Malaysia",17200
|
||||
"Botswana",17100
|
||||
"Gabon",16800
|
||||
"Saint Kitts and Nevis",16500
|
||||
"Puerto Rico",16300
|
||||
"Uruguay",16200
|
||||
"Lebanon",16000
|
||||
"Panama",15900
|
||||
"Belarus",15900
|
||||
"Mauritius",15800
|
||||
"Mexico",15600
|
||||
"Sint Maarten",15400
|
||||
"Turkey",15200
|
||||
"Curacao",15000
|
||||
"Bulgaria",14500
|
||||
"Virgin Islands",14500
|
||||
"Dominica",14400
|
||||
"Kazakhstan",14100
|
||||
"Grenada",13900
|
||||
"Venezuela",13800
|
||||
"Northern Mariana Islands",13600
|
||||
"Iran",13300
|
||||
"Saint Lucia",13300
|
||||
"Romania",13000
|
||||
"Costa Rica",12800
|
||||
"Suriname",12600
|
||||
"Libya",12300
|
||||
"Anguilla",12200
|
||||
"Brazil",12100
|
||||
"Saint Vincent and the Grenadines",12000
|
||||
"Montenegro",12000
|
||||
"South Africa",11600
|
||||
"Colombia",11000
|
||||
"Peru",10900
|
||||
"Macedonia",10800
|
||||
"Azerbaijan",10700
|
||||
"Serbia",10600
|
||||
"Palau",10500
|
||||
"Thailand",10300
|
||||
"Ecuador",10200
|
||||
"Cuba",10200
|
||||
"Timor-Leste",10000
|
||||
"Tunisia",9900
|
||||
"Dominican Republic",9800
|
||||
"Maldives",9400
|
||||
"China",9300
|
||||
"Jamaica",9300
|
||||
"Cook Islands",9100
|
||||
"Belize",8900
|
||||
"Turkmenistan",8900
|
||||
"Marshall Islands",8800
|
||||
"Montserrat",8500
|
||||
"Bosnia and Herzegovina",8400
|
||||
"Albania",8200
|
||||
"Guyana",8100
|
||||
"American Samoa",8000
|
||||
"Namibia",7900
|
||||
"Saint Helena, Ascension, and Tristan da Cunha",7800
|
||||
"Tonga",7700
|
||||
"El Salvador",7600
|
||||
"Algeria",7600
|
||||
"Ukraine",7500
|
||||
"Micronesia, Federated States of",7500
|
||||
"Iraq",7200
|
||||
"Bhutan",6800
|
||||
"Egypt",6700
|
||||
"Angola",6500
|
||||
"Samoa",6300
|
||||
"Paraguay",6200
|
||||
"Sri Lanka",6200
|
||||
"Kiribati",6100
|
||||
"Jordan",6100
|
||||
"Georgia",6000
|
||||
"Swaziland",5900
|
||||
"Armenia",5900
|
||||
"Niue",5800
|
||||
"Mongolia",5500
|
||||
"Morocco",5400
|
||||
"Guatemala",5300
|
||||
"Bolivia",5200
|
||||
"Indonesia",5100
|
||||
"Syria",5100
|
||||
"Nauru",5000
|
||||
"Vanuatu",5000
|
||||
"Fiji",4900
|
||||
"Honduras",4700
|
||||
"Congo, Republic of the",4700
|
||||
"Philippines",4500
|
||||
"Nicaragua",4500
|
||||
"Cape Verde",4200
|
||||
"India",3900
|
||||
"Wallis and Futuna",3800
|
||||
"Vietnam",3600
|
||||
"Uzbekistan",3600
|
||||
"Moldova",3500
|
||||
"Ghana",3400
|
||||
"Tuvalu",3400
|
||||
"Solomon Islands",3400
|
||||
"Laos",3100
|
||||
"Pakistan",2900
|
||||
"West Bank",2900
|
||||
"Papua New Guinea",2800
|
||||
"Nigeria",2800
|
||||
"Djibouti",2700
|
||||
"Sudan",2600
|
||||
"Western Sahara",2500
|
||||
"Cambodia",2400
|
||||
"Kyrgyzstan",2400
|
||||
"Sao Tome and Principe",2400
|
||||
"Cameroon",2400
|
||||
"Yemen",2300
|
||||
"Tajikistan",2300
|
||||
"Mauritania",2200
|
||||
"Lesotho",2200
|
||||
"Senegal",2100
|
||||
"Bangladesh",2100
|
||||
"Chad",2000
|
||||
"Gambia, The",1900
|
||||
"Cote d'Ivoire",1800
|
||||
"Korea, North",1800
|
||||
"Kenya",1800
|
||||
"Zambia",1700
|
||||
"Benin",1700
|
||||
"Tanzania",1600
|
||||
"Rwanda",1500
|
||||
"Burkina Faso",1400
|
||||
"Uganda",1400
|
||||
"Sierra Leone",1400
|
||||
"Burma",1400
|
||||
"Comoros",1300
|
||||
"Haiti",1300
|
||||
"Nepal",1300
|
||||
"Ethiopia",1200
|
||||
"Guinea-Bissau",1200
|
||||
"Mozambique",1200
|
||||
"Guinea",1100
|
||||
"Afghanistan",1100
|
||||
"Mali",1100
|
||||
"Togo",1100
|
||||
"South Sudan",1000
|
||||
"Madagascar",1000
|
||||
"Tokelau",1000
|
||||
"Malawi",900
|
||||
"Central African Republic",800
|
||||
"Niger",800
|
||||
"Eritrea",800
|
||||
"Liberia",700
|
||||
"Burundi",600
|
||||
"Zimbabwe",600
|
||||
"Somalia",600
|
||||
"Congo, Democratic Republic of the",400
|
||||
"Kosovo",0
|
||||
|
@@ -0,0 +1,7 @@
|
||||
Library,Github Stars,Forks,Watchers
|
||||
React.js,169000,34000,6700
|
||||
Vue,184000,29100,6300
|
||||
Angular,73400,19300,3200
|
||||
JQuery,54900,20000,3300
|
||||
Meteor,42400,5200,1700
|
||||
Aurelia,11600,684,442
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
State, 2020, 2000, 1980
|
||||
California, 39368078,33987977,23800800
|
||||
Texas, 29360759, 20944499, 14338208
|
||||
Florida, 21733312, 16047515, 9839835
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user