2016-08-10 17:27:39 +02:00
|
|
|
package imguploader
|
|
|
|
|
|
|
|
|
|
import (
|
2017-09-15 15:46:41 +02:00
|
|
|
"context"
|
2021-07-02 19:22:47 +08:00
|
|
|
"strings"
|
2016-08-10 17:27:39 +02:00
|
|
|
"testing"
|
|
|
|
|
|
2023-09-27 23:35:10 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-07-02 19:22:47 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-08-10 17:27:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestUploadToWebdav(t *testing.T) {
|
2017-04-25 17:20:03 +02:00
|
|
|
// Can be tested with this docker container: https://hub.docker.com/r/morrisjobke/webdav/
|
2021-07-02 19:22:47 +08: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")
|
2017-04-25 17:20:03 +02:00
|
|
|
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "")
|
2017-09-15 15:46:41 +02:00
|
|
|
path, err := webdavUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png")
|
2016-08-10 17:27:39 +02:00
|
|
|
|
2021-07-02 19:22:47 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.True(t, strings.HasPrefix(path, "http://localhost:8888/webdav/"))
|
2017-04-25 17:20:03 +02:00
|
|
|
})
|
|
|
|
|
|
2021-07-02 19:22:47 +08: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")
|
2017-04-25 17:20:03 +02:00
|
|
|
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://publicurl:8888/webdav")
|
2017-09-15 15:46:41 +02:00
|
|
|
path, err := webdavUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png")
|
2017-04-25 17:20:03 +02:00
|
|
|
|
2021-07-02 19:22:47 +08: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/"))
|
2016-08-10 17:27:39 +02:00
|
|
|
})
|
|
|
|
|
}
|
2018-07-17 20:10:12 +02:00
|
|
|
|
|
|
|
|
func TestPublicURL(t *testing.T) {
|
2021-07-02 19:22:47 +08:00
|
|
|
t.Run("Given a public URL with parameters, and no template", func(t *testing.T) {
|
2018-07-17 20:10:12 +02:00
|
|
|
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files=")
|
2023-09-27 23:35:10 +02:00
|
|
|
assert.Equal(t, "http://cloudycloud.me/s/DOIFDOMV/download/fileyfile.png?files=", webdavUploader.PublicURL("fileyfile.png"))
|
2018-07-17 20:10:12 +02:00
|
|
|
})
|
2021-07-02 19:22:47 +08:00
|
|
|
t.Run("Given a public URL with parameters, and a template", func(t *testing.T) {
|
2023-09-27 23:35:10 +02:00
|
|
|
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files={{file}}")
|
|
|
|
|
assert.Equal(t, "http://cloudycloud.me/s/DOIFDOMV/download?files=fileyfile.png", webdavUploader.PublicURL("fileyfile.png"))
|
2018-07-17 20:10:12 +02:00
|
|
|
})
|
|
|
|
|
}
|