* move upload to http * use storage from grafanads * rever gomod changes * fix test * wip * add upload func * update upload func * writing to uploads * edit response from service * use dropzone for UI * modify response struct in service * better read file * set content type for svg * restrict file types upload * add test and clean up errors * pass test * fix backend lint errors * limit type of files on FE * add TODO for after merge * rebase with storage changes * comment out unused function * update UI to not have 2 uploads * only call upload on select * use utils function to find * in path * show preview on drag over * not allowing upload of svg * add preview to upload tab * no console.log * resolve conflicts * refactor log line * fix failing BE test Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Artur Wierzbicki <artur.wierzbicki@grafana.com>
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package store
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"mime/multipart"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/experimental"
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/tsdb/testdatasource"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestListFiles(t *testing.T) {
|
|
publicRoot, err := filepath.Abs("../../../public")
|
|
require.NoError(t, err)
|
|
roots := []storageRuntime{
|
|
newDiskStorage("public", "Public static files", &StorageLocalDiskConfig{
|
|
Path: publicRoot,
|
|
Roots: []string{
|
|
"/testdata/",
|
|
"/img/icons/",
|
|
"/img/bg/",
|
|
"/gazetteer/",
|
|
"/maps/",
|
|
"/upload/",
|
|
},
|
|
}).setReadOnly(true).setBuiltin(true),
|
|
}
|
|
|
|
store := newStandardStorageService(roots)
|
|
frame, err := store.List(context.Background(), nil, "public/testdata")
|
|
require.NoError(t, err)
|
|
|
|
err = experimental.CheckGoldenFrame(path.Join("testdata", "public_testdata.golden.txt"), frame, true)
|
|
require.NoError(t, err)
|
|
|
|
file, err := store.Read(context.Background(), nil, "public/testdata/js_libraries.csv")
|
|
require.NoError(t, err)
|
|
require.NotNil(t, file)
|
|
|
|
frame, err = testdatasource.LoadCsvContent(bytes.NewReader(file.Contents), file.Name)
|
|
require.NoError(t, err)
|
|
err = experimental.CheckGoldenFrame(path.Join("testdata", "public_testdata_js_libraries.golden.txt"), frame, true)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestUpload(t *testing.T) {
|
|
features := featuremgmt.WithFeatures(featuremgmt.FlagStorageLocalUpload)
|
|
path, err := os.Getwd()
|
|
require.NoError(t, err)
|
|
cfg := &setting.Cfg{AppURL: "http://localhost:3000/", DataPath: path}
|
|
s := ProvideService(nil, features, cfg)
|
|
testForm := &multipart.Form{
|
|
Value: map[string][]string{},
|
|
File: map[string][]*multipart.FileHeader{},
|
|
}
|
|
res, err := s.Upload(context.Background(), nil, testForm)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, res.path, "upload")
|
|
}
|