grafana/pkg/components/imguploader/webdavuploader_test.go

46 lines
2.0 KiB
Go
Raw Normal View History

package imguploader
import (
2017-09-15 08:46:41 -05:00
"context"
"net/url"
2021-07-02 06:22:47 -05:00
"strings"
"testing"
2021-07-02 06:22:47 -05:00
"github.com/stretchr/testify/require"
)
func TestUploadToWebdav(t *testing.T) {
// Can be tested with this docker container: https://hub.docker.com/r/morrisjobke/webdav/
2021-07-02 06:22:47 -05:00
t.Run("[Integration test] for external_image_store.webdav", func(t *testing.T) {
t.Skip("Skip test [Integration test] for external_image_store.webdav")
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "")
2017-09-15 08:46:41 -05:00
path, err := webdavUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png")
2021-07-02 06:22:47 -05:00
require.NoError(t, err)
require.True(t, strings.HasPrefix(path, "http://localhost:8888/webdav/"))
})
2021-07-02 06:22:47 -05:00
t.Run("[Integration test] for external_image_store.webdav with public url", func(t *testing.T) {
t.Skip("Skip test [Integration test] for external_image_store.webdav with public url")
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://publicurl:8888/webdav")
2017-09-15 08:46:41 -05:00
path, err := webdavUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png")
2021-07-02 06:22:47 -05:00
require.NoError(t, err)
require.True(t, strings.HasPrefix(path, "http://publicurl:8888/webdav/"))
require.True(t, strings.HasPrefix(path, "http://publicurl:8888/webdav/"))
})
}
func TestPublicURL(t *testing.T) {
2021-07-02 06:22:47 -05:00
t.Run("Given a public URL with parameters, and no template", func(t *testing.T) {
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files=")
parsed, _ := url.Parse(webdavUploader.PublicURL("fileyfile.png"))
2021-07-02 06:22:47 -05:00
require.True(t, strings.HasSuffix(parsed.Path, "fileyfile.png"))
})
2021-07-02 06:22:47 -05:00
t.Run("Given a public URL with parameters, and a template", func(t *testing.T) {
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files=${file}")
2021-07-02 06:22:47 -05:00
require.True(t, strings.HasSuffix(webdavUploader.PublicURL("fileyfile.png"), "fileyfile.png"))
})
}