webdav: add tests + path.join for public url param

Fixes #7914. Fixes #7921
This commit is contained in:
Daniel Lee 2017-04-25 17:20:03 +02:00
parent 6d9e8bd147
commit 6538e86793
4 changed files with 18 additions and 7 deletions

View File

@ -645,7 +645,7 @@ Secret key. e.g. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Url to where Grafana will send PUT request with images
### 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
basic auth username

View File

@ -8,7 +8,7 @@ import (
)
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{
HomePath: "../../../",
})

View File

@ -56,10 +56,12 @@ func (u *WebdavUploader) Upload(pa string) (string, error) {
}
if u.public_url != "" {
return (u.public_url + filename), nil
} else {
return url.String(), nil
publicURL, _ := url.Parse(u.public_url)
publicURL.Path = path.Join(publicURL.Path, filename)
return publicURL.String(), nil
}
return url.String(), nil
}
func NewWebdavImageUploader(url, username, password, public_url string) (*WebdavUploader, error) {

View File

@ -7,12 +7,21 @@ import (
)
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() {
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "")
path, err := webdavUploader.Upload("../../../public/img/logo_transparent_400x.png")
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/")
})
}