40 lines
811 B
Go
40 lines
811 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func Test_DefaultLinkHandler(t *testing.T) {
|
|
client = &http.Client{
|
|
Timeout: 10 * time.Second,
|
|
}
|
|
|
|
type expectedData struct {
|
|
Link string
|
|
Title string
|
|
Type string
|
|
}
|
|
|
|
testLinks := []expectedData{
|
|
{"https://paste.ee", "Paste.ee", "text/html"},
|
|
{"http://techslides.com/demos/sample-videos/small.mp4", "", "video/mp4"},
|
|
}
|
|
|
|
for _, link := range testLinks {
|
|
l, err := defaultLinkHandler(link.Link)
|
|
|
|
if err != nil {
|
|
t.Fatal("Unable to retrieve link info:", err)
|
|
}
|
|
|
|
if link.Title != "" && link.Title != l.Title {
|
|
t.Fatal("Unexpected title, expected:", link.Title, "got:", l.Title)
|
|
}
|
|
|
|
if link.Type != "" && link.Type != l.ContentType {
|
|
t.Fatal("Unexpected content type, expected:", link.Type, "got:", l.ContentType)
|
|
}
|
|
}
|
|
} |