-
Notifications
You must be signed in to change notification settings - Fork 15
/
finder_thesubdb_test.go
53 lines (39 loc) · 1.36 KB
/
finder_thesubdb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// +build network
package subtitles
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDownloadFromTheSubDb(t *testing.T) {
fileName := createZeroedTempFile(1024 * 1024 * 4)
defer os.Remove(fileName)
f, err := os.Open(fileName)
assert.Equal(t, nil, err)
hash, err := SubDbHashFromFile(f)
assert.Equal(t, nil, err)
assert.Equal(t, "0dfbe8aa4c20b52e1b8bf3cb6cbdf193", hash)
finder := NewSubFinder(f, fileName, "en")
text, err := finder.TheSubDb("sandbox.thesubdb.com")
assert.Equal(t, nil, err)
assert.True(t, len(text) > 1000)
}
func subDbConformTest(t *testing.T, fileName string, expectedHash string) {
if !exists(fileName) {
fmt.Println("ERROR thesubdb.com conformance tests missing, run ./hash-conformance-deps if you want to run these tests")
return
}
f, err := os.Open(fileName)
assert.Equal(t, nil, err)
hash, err := SubDbHashFromFile(f)
assert.Equal(t, nil, err)
assert.Equal(t, expectedHash, hash)
}
func TestSubDbHashFromFile(t *testing.T) {
// NOTE for this to work, run "./hash-conformance-deps" to fetch needed files
// http://thesubdb.com/api/samples/dexter.mp4
subDbConformTest(t, "conformance-files/thesubdb/dexter.mp4", "ffd8d4aa68033dc03d1c8ef373b9028c")
// http://thesubdb.com/api/samples/justified.mp4
subDbConformTest(t, "conformance-files/thesubdb/justified.mp4", "edc1981d6459c6111fe36205b4aff6c2")
}