tiktok-dl/models/upload_test.go

69 lines
2.2 KiB
Go
Raw Normal View History

2020-01-19 02:11:53 +00:00
package models
2020-01-21 23:06:35 +00:00
import (
testUtil "../unitTestUtil"
utils "../utils"
"os"
"testing"
)
2020-01-19 02:11:53 +00:00
func TestParseUploads(t *testing.T) {
2020-01-21 23:06:35 +00:00
tu := testUtil.TestUtil{T: t}
jsonStr := "[{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\", \"uploader\": \"some.uploader\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}]"
2020-01-19 02:11:53 +00:00
actual := ParseUploads(jsonStr)
2020-01-21 23:06:35 +00:00
tu.AssertInt(len(actual), 1, "Array len")
2020-01-19 02:11:53 +00:00
2020-01-21 23:06:35 +00:00
tu.AssertString(actual[0].URL, "some_url", "URL")
tu.AssertString(actual[0].Caption, "some_caption", "Caption")
tu.AssertString(actual[0].ShareLink, "some_share_link", "ShareLink")
tu.AssertString(actual[0].Uploader, "some.uploader", "Uploader")
2020-01-19 02:11:53 +00:00
2020-01-21 23:06:35 +00:00
tu.AssertString(actual[0].Sound.Link, "some_link", "Sound.Link")
tu.AssertString(actual[0].Sound.Title, "some_title", "Sound.Title")
}
func TestParseUpload(t *testing.T) {
tu := testUtil.TestUtil{T: t}
jsonStr := "{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}"
actual := ParseUpload(jsonStr)
tu.AssertString(actual.URL, "some_url", "URL")
tu.AssertString(actual.Caption, "some_caption", "Caption")
tu.AssertString(actual.ShareLink, "some_share_link", "ShareLink")
tu.AssertString(actual.Sound.Link, "some_link", "Sound.Link")
tu.AssertString(actual.Sound.Title, "some_title", "Sound.Title")
2020-01-19 02:11:53 +00:00
}
func TestGetUploadID(t *testing.T) {
2020-01-21 23:06:35 +00:00
tu := testUtil.TestUtil{T: t}
2020-01-19 02:11:53 +00:00
var upload Upload
upload.ShareLink = "http://pikami.org/some_thing/some_upload_id"
actual := upload.GetUploadID()
2020-01-21 23:06:35 +00:00
tu.AssertString(actual, "some_upload_id", "Upload ID")
}
func TestWriteToFile(t *testing.T) {
tu := testUtil.TestUtil{T: t}
expected := "{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}"
filePath := "test_file.txt"
upload := Upload{
URL: "some_url",
Caption: "some_caption",
ShareLink: "some_share_link",
Sound: Sound{
Link: "some_link",
Title: "some_title",
},
2020-01-19 02:11:53 +00:00
}
2020-01-21 23:06:35 +00:00
upload.WriteToFile(filePath)
actual := utils.ReadFileToString(filePath)
tu.AssertString(actual, expected, "File content")
os.Remove(filePath)
2020-01-19 02:11:53 +00:00
}