2020-04-05 22:26:53 +02:00
|
|
|
package remote
|
2020-03-29 11:29:02 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDiscover(t *testing.T) {
|
|
|
|
t.Run("webdav", func(t *testing.T) {
|
2021-11-09 16:55:16 +01:00
|
|
|
r, err := Discover("http://admin:photoprism@dummy-webdav/", "", "")
|
2020-03-29 11:29:02 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-09 16:55:16 +01:00
|
|
|
assert.Equal(t, "Dummy-Webdav", r.AccName)
|
2020-03-29 11:29:02 +02:00
|
|
|
assert.Equal(t, "webdav", r.AccType)
|
2021-11-09 16:55:16 +01:00
|
|
|
assert.Equal(t, "http://dummy-webdav/", r.AccURL)
|
2020-03-29 11:29:02 +02:00
|
|
|
assert.Equal(t, "admin", r.AccUser)
|
|
|
|
assert.Equal(t, "photoprism", r.AccPass)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("webdav password", func(t *testing.T) {
|
2021-11-09 16:55:16 +01:00
|
|
|
r, err := Discover("http://admin@dummy-webdav/", "", "photoprism")
|
2020-03-29 11:29:02 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-09 16:55:16 +01:00
|
|
|
assert.Equal(t, "Dummy-Webdav", r.AccName)
|
2020-03-29 11:29:02 +02:00
|
|
|
assert.Equal(t, "webdav", r.AccType)
|
2021-11-09 16:55:16 +01:00
|
|
|
assert.Equal(t, "http://dummy-webdav/", r.AccURL)
|
2020-03-29 11:29:02 +02:00
|
|
|
assert.Equal(t, "admin", r.AccUser)
|
|
|
|
assert.Equal(t, "photoprism", r.AccPass)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("facebook", func(t *testing.T) {
|
2021-02-22 21:09:50 +01:00
|
|
|
r, err := Discover("https://www.facebook.com/terms", "test", "")
|
2020-03-29 11:29:02 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:17:46 +02:00
|
|
|
assert.Equal(t, "Facebook", r.AccName)
|
2020-03-29 11:29:02 +02:00
|
|
|
assert.Equal(t, "facebook", r.AccType)
|
2021-02-22 21:09:50 +01:00
|
|
|
assert.Equal(t, "https://www.facebook.com/terms", r.AccURL)
|
2020-04-29 13:19:07 +02:00
|
|
|
assert.Equal(t, "test", r.AccUser)
|
|
|
|
assert.Equal(t, "", r.AccPass)
|
|
|
|
})
|
|
|
|
t.Run("empty raw url", func(t *testing.T) {
|
|
|
|
r, err := Discover("", "", "")
|
|
|
|
|
|
|
|
assert.Equal(t, err.Error(), "service URL is empty")
|
|
|
|
assert.Equal(t, "", r.AccName)
|
|
|
|
assert.Equal(t, "", r.AccType)
|
|
|
|
assert.Equal(t, "", r.AccURL)
|
|
|
|
assert.Equal(t, "", r.AccUser)
|
|
|
|
assert.Equal(t, "", r.AccPass)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid raw url", func(t *testing.T) {
|
|
|
|
r, err := Discover("xxx", "", "")
|
|
|
|
|
|
|
|
assert.Equal(t, err.Error(), "could not connect")
|
|
|
|
assert.Equal(t, "", r.AccName)
|
|
|
|
assert.Equal(t, "", r.AccType)
|
|
|
|
assert.Equal(t, "", r.AccURL)
|
2020-03-29 11:29:02 +02:00
|
|
|
assert.Equal(t, "", r.AccUser)
|
|
|
|
assert.Equal(t, "", r.AccPass)
|
|
|
|
})
|
|
|
|
}
|