webdavuploader_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package imguploader
  2. import (
  3. "context"
  4. "net/url"
  5. "testing"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestUploadToWebdav(t *testing.T) {
  9. // Can be tested with this docker container: https://hub.docker.com/r/morrisjobke/webdav/
  10. SkipConvey("[Integration test] for external_image_store.webdav", t, func() {
  11. webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "")
  12. path, err := webdavUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png")
  13. So(err, ShouldBeNil)
  14. So(path, ShouldStartWith, "http://localhost:8888/webdav/")
  15. })
  16. SkipConvey("[Integration test] for external_image_store.webdav with public url", t, func() {
  17. webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://publicurl:8888/webdav")
  18. path, err := webdavUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png")
  19. So(err, ShouldBeNil)
  20. So(path, ShouldStartWith, "http://publicurl:8888/webdav/")
  21. })
  22. }
  23. func TestPublicURL(t *testing.T) {
  24. Convey("Given a public URL with parameters, and no template", t, func() {
  25. webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files=")
  26. parsed, _ := url.Parse(webdavUploader.PublicURL("fileyfile.png"))
  27. So(parsed.Path, ShouldEndWith, "fileyfile.png")
  28. })
  29. Convey("Given a public URL with parameters, and a template", t, func() {
  30. webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files=${file}")
  31. So(webdavUploader.PublicURL("fileyfile.png"), ShouldEndWith, "fileyfile.png")
  32. })
  33. }