mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 00:37:04 -06:00
webdav: add tests + path.join for public url param
Fixes #7914. Fixes #7921
This commit is contained in:
parent
6d9e8bd147
commit
6538e86793
@ -645,7 +645,7 @@ Secret key. e.g. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|||||||
Url to where Grafana will send PUT request with images
|
Url to where Grafana will send PUT request with images
|
||||||
|
|
||||||
### public_url
|
### public_url
|
||||||
Url to send to users in notifications, directly appended with the resulting uploaded file name
|
Optional parameter. Url to send to users in notifications, directly appended with the resulting uploaded file name.
|
||||||
|
|
||||||
### username
|
### username
|
||||||
basic auth username
|
basic auth username
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestUploadToS3(t *testing.T) {
|
func TestUploadToS3(t *testing.T) {
|
||||||
SkipConvey("[Integration test] for external_image_store.webdav", t, func() {
|
SkipConvey("[Integration test] for external_image_store.s3", t, func() {
|
||||||
setting.NewConfigContext(&setting.CommandLineArgs{
|
setting.NewConfigContext(&setting.CommandLineArgs{
|
||||||
HomePath: "../../../",
|
HomePath: "../../../",
|
||||||
})
|
})
|
||||||
|
@ -56,10 +56,12 @@ func (u *WebdavUploader) Upload(pa string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if u.public_url != "" {
|
if u.public_url != "" {
|
||||||
return (u.public_url + filename), nil
|
publicURL, _ := url.Parse(u.public_url)
|
||||||
} else {
|
publicURL.Path = path.Join(publicURL.Path, filename)
|
||||||
return url.String(), nil
|
return publicURL.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return url.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebdavImageUploader(url, username, password, public_url string) (*WebdavUploader, error) {
|
func NewWebdavImageUploader(url, username, password, public_url string) (*WebdavUploader, error) {
|
||||||
|
@ -7,12 +7,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestUploadToWebdav(t *testing.T) {
|
func TestUploadToWebdav(t *testing.T) {
|
||||||
webdavUploader, _ := NewWebdavImageUploader("http://localhost:9998/dav/", "username", "password", "")
|
|
||||||
|
|
||||||
|
// Can be tested with this docker container: https://hub.docker.com/r/morrisjobke/webdav/
|
||||||
SkipConvey("[Integration test] for external_image_store.webdav", t, func() {
|
SkipConvey("[Integration test] for external_image_store.webdav", t, func() {
|
||||||
|
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "")
|
||||||
path, err := webdavUploader.Upload("../../../public/img/logo_transparent_400x.png")
|
path, err := webdavUploader.Upload("../../../public/img/logo_transparent_400x.png")
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(path, ShouldNotEqual, "")
|
So(path, ShouldStartWith, "http://localhost:8888/webdav/")
|
||||||
|
})
|
||||||
|
|
||||||
|
SkipConvey("[Integration test] for external_image_store.webdav with public url", t, func() {
|
||||||
|
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://publicurl:8888/webdav")
|
||||||
|
path, err := webdavUploader.Upload("../../../public/img/logo_transparent_400x.png")
|
||||||
|
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(path, ShouldStartWith, "http://publicurl:8888/webdav/")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user