-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicate-finder_test.go
62 lines (48 loc) · 1.62 KB
/
duplicate-finder_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
54
55
56
57
58
59
60
61
62
package goautowp
import (
"context"
"testing"
"github.com/autowp/goautowp/config"
"github.com/autowp/goautowp/image/storage"
"github.com/autowp/goautowp/schema"
"github.com/stretchr/testify/require"
)
func TestDuplicateFinder(t *testing.T) {
t.Parallel()
cfg := config.LoadConfig(".")
goquDB, err := cnt.GoquDB()
require.NoError(t, err)
df, err := NewDuplicateFinder(goquDB)
require.NoError(t, err)
ctx := context.Background()
imageStorage, err := storage.NewStorage(goquDB, cfg.ImageStorage)
require.NoError(t, err)
id1, _ := addPicture(t, imageStorage, goquDB, "./test/large.jpg")
err = df.Index(ctx, id1, "http://localhost:80/large.jpg")
require.NoError(t, err)
id2, _ := addPicture(t, imageStorage, goquDB, "./test/small.jpg")
err = df.Index(ctx, id2, "http://localhost:80/small.jpg")
require.NoError(t, err)
var hash1 uint64
success, err := goquDB.Select(schema.DfHashTableHashCol).
From(schema.DfHashTable).
Where(schema.DfHashTablePictureIDCol.Eq(id1)).
ScanValContext(ctx, &hash1)
require.NoError(t, err)
require.True(t, success)
var hash2 uint64
success, err = goquDB.Select(schema.DfHashTableHashCol).
From(schema.DfHashTable).
Where(schema.DfHashTablePictureIDCol.Eq(id2)).
ScanValContext(ctx, &hash2)
require.NoError(t, err)
require.True(t, success)
var distance int
success, err = goquDB.Select(schema.DfDistanceTableDistanceCol).From(schema.DfDistanceTable).Where(
schema.DfDistanceTableSrcPictureIDCol.Eq(id1),
schema.DfDistanceTableDstPictureIDCol.Eq(id2),
).ScanValContext(ctx, &distance)
require.NoError(t, err)
require.True(t, success)
require.LessOrEqual(t, distance, 2)
}