2020-02-07 23:51:17 +00:00
|
|
|
package utils
|
2020-01-21 23:06:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-04-12 01:22:00 +01:00
|
|
|
|
|
|
|
config "github.com/pikami/tiktok-dl/models/config"
|
|
|
|
testUtil "github.com/pikami/tiktok-dl/unitTestUtil"
|
2020-01-21 23:06:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetUsername(t *testing.T) {
|
|
|
|
testCaseDelegate := func(t *testing.T, url string, username string) {
|
|
|
|
tu := testUtil.TestUtil{T: t}
|
2020-02-07 23:51:17 +00:00
|
|
|
config.Config.URL = url
|
2020-01-21 23:06:35 +00:00
|
|
|
actual := GetUsername()
|
|
|
|
tu.AssertString(actual, username, "Username")
|
|
|
|
}
|
|
|
|
|
|
|
|
testVideoURL := func(t *testing.T) {
|
|
|
|
testCaseDelegate(t, "https://www.tiktok.com/@some_username/video/0000000000000000000", "some_username")
|
|
|
|
}
|
|
|
|
|
|
|
|
testProfileURL := func(t *testing.T) {
|
|
|
|
testCaseDelegate(t, "https://www.tiktok.com/@some_username", "some_username")
|
|
|
|
}
|
|
|
|
|
|
|
|
testPlainUsername := func(t *testing.T) {
|
|
|
|
testCaseDelegate(t, "some_username", "some_username")
|
|
|
|
}
|
|
|
|
|
|
|
|
testAtUsername := func(t *testing.T) {
|
|
|
|
testCaseDelegate(t, "@some_username", "some_username")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Video URL", testVideoURL)
|
|
|
|
t.Run("Username URL", testProfileURL)
|
|
|
|
t.Run("Plain username", testPlainUsername)
|
|
|
|
t.Run("Username with @ suffix", testAtUsername)
|
|
|
|
}
|