Просмотр исходного кода

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

Fixes #7914. Fixes #7921
Daniel Lee 8 лет назад
Родитель
Сommit
6538e86793

+ 1 - 1
docs/sources/installation/configuration.md

@@ -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

+ 1 - 1
pkg/components/imguploader/s3uploader_test.go

@@ -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: "../../../",
 		})
 		})

+ 5 - 3
pkg/components/imguploader/webdavuploader.go

@@ -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
-	} 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) {
 func NewWebdavImageUploader(url, username, password, public_url string) (*WebdavUploader, error) {

+ 11 - 2
pkg/components/imguploader/webdavuploader_test.go

@@ -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/")
 	})
 	})
 }
 }