aboutsummaryrefslogtreecommitdiffstats
path: root/skate
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-06-10 16:50:07 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-06-10 16:50:07 +0200
commit77a4e8d43c87d3582bc86696551f48cc47c688bb (patch)
tree39d9a86d415b0402fe58b622490ce4d518195ee7 /skate
parentea54e8231c9f6f4f3116b3b9a60074c3229257d6 (diff)
downloadrefcat-77a4e8d43c87d3582bc86696551f48cc47c688bb.tar.gz
refcat-77a4e8d43c87d3582bc86696551f48cc47c688bb.zip
add test cases
Diffstat (limited to 'skate')
-rw-r--r--skate/go.mod1
-rw-r--r--skate/zippy.go4
-rw-r--r--skate/zippy_test.go58
3 files changed, 60 insertions, 3 deletions
diff --git a/skate/go.mod b/skate/go.mod
index a3d7501..5a16156 100644
--- a/skate/go.mod
+++ b/skate/go.mod
@@ -7,6 +7,7 @@ require (
github.com/elastic/go-elasticsearch v0.0.0
github.com/elastic/go-elasticsearch/v7 v7.12.0
github.com/klauspost/cpuid/v2 v2.0.6 // indirect
+ github.com/kr/pretty v0.1.0 // indirect
github.com/matryer/is v1.4.0
github.com/nsf/jsondiff v0.0.0-20210303162244-6ea32392771e
github.com/segmentio/encoding v0.2.17
diff --git a/skate/zippy.go b/skate/zippy.go
index bd7bf70..1dbf6aa 100644
--- a/skate/zippy.go
+++ b/skate/zippy.go
@@ -319,7 +319,7 @@ func ZippyVerifyRefsOpenLibrary(olr, refs io.Reader, w io.Writer) error {
// We can identify, which docs have been matched by checking the ref key and index.
func ZippyBrefAugment(bref, raw io.Reader, w io.Writer) error {
var (
- enc = json.NewEncoder(w)
+ _ = json.NewEncoder(w)
keyer = makeKeyFunc("\t", 1)
grouper = func(g *zipkey.Group) error {
// g.G0 contains a matched docs for a given work id, g.G1 all raw
@@ -327,7 +327,7 @@ func ZippyBrefAugment(bref, raw io.Reader, w io.Writer) error {
// First, iterate over all matches and sort out duplicates, e.g.
// docs that have the same source and target id.
- uniqueBref, err := uniqueMatches(g.G0)
+ _, err := uniqueMatches(g.G0)
if err != nil {
return err
}
diff --git a/skate/zippy_test.go b/skate/zippy_test.go
index 1448472..7fd32ae 100644
--- a/skate/zippy_test.go
+++ b/skate/zippy_test.go
@@ -1,6 +1,11 @@
package skate
-import "testing"
+import (
+ "reflect"
+ "testing"
+
+ "github.com/kr/pretty"
+)
func TestLineColumn(t *testing.T) {
var cases = []struct {
@@ -23,3 +28,54 @@ func TestLineColumn(t *testing.T) {
}
}
}
+
+func TestUniqueMatches(t *testing.T) {
+ var cases = []struct {
+ docs []string
+ result []*BiblioRef
+ err error
+ }{
+ {
+ docs: []string{`{}`},
+ result: []*BiblioRef{&BiblioRef{}},
+ err: nil,
+ },
+ {
+ docs: []string{`{
+ "source_release_ident": "s1",
+ "target_release_ident": "t1"}`},
+ result: []*BiblioRef{&BiblioRef{
+ SourceReleaseIdent: "s1",
+ TargetReleaseIdent: "t1",
+ }},
+ err: nil,
+ },
+ {
+ docs: []string{`
+ {"source_release_ident": "s1",
+ "target_release_ident": "t1",
+ "match_status": "fuzzy"}`,
+ `{"source_release_ident": "s1",
+ "target_release_ident": "t1",
+ "match_status": "exact"}`,
+ },
+ result: []*BiblioRef{&BiblioRef{
+ SourceReleaseIdent: "s1",
+ TargetReleaseIdent: "t1",
+ MatchStatus: "exact",
+ }},
+ err: nil,
+ },
+ }
+ for _, c := range cases {
+ result, err := uniqueMatches(c.docs)
+ if err != c.err {
+ t.Fatalf("got %v, want %v", err, c.err)
+ }
+ if !reflect.DeepEqual(result, c.result) {
+ t.Fatalf("got %#v, want %#v",
+ pretty.Sprint(result),
+ pretty.Sprint(c.result))
+ }
+ }
+}