Switch from Godep to go vendoring

This commit is contained in:
Ken-Håvard Lieng 2016-03-01 01:51:26 +01:00
parent 6b37713bc0
commit cd317761c5
1504 changed files with 263076 additions and 34441 deletions

View file

@ -0,0 +1,22 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package test
import (
"github.com/blevesearch/bleve"
)
type SearchTest struct {
Search *bleve.SearchRequest `json:"search"`
Result *bleve.SearchResult `json:"result"`
Comment string `json:"comment"`
}
type SearchTests []*SearchTest

View file

@ -0,0 +1,163 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package test
import (
"encoding/json"
"flag"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"regexp"
"testing"
"github.com/blevesearch/bleve"
)
var dataset = flag.String("dataset", "", "only test datasets matching this regex")
var keepIndex = flag.Bool("keepIndex", false, "keep the index after testing")
func TestIntegration(t *testing.T) {
flag.Parse()
var err error
var datasetRegexp *regexp.Regexp
if *dataset != "" {
datasetRegexp, err = regexp.Compile(*dataset)
if err != nil {
t.Fatal(err)
}
}
fis, err := ioutil.ReadDir("tests")
if err != nil {
t.Fatal(err)
}
for _, fi := range fis {
if datasetRegexp != nil {
if !datasetRegexp.MatchString(fi.Name()) {
continue
}
}
if fi.IsDir() {
t.Logf("Running test: %s", fi.Name())
runTestDir(t, "tests"+string(filepath.Separator)+fi.Name())
}
}
}
func runTestDir(t *testing.T, dir string) {
// read the mapping
mappingBytes, err := ioutil.ReadFile(dir + string(filepath.Separator) + "mapping.json")
if err != nil {
t.Errorf("error reading mapping: %v", err)
return
}
var mapping bleve.IndexMapping
err = json.Unmarshal(mappingBytes, &mapping)
if err != nil {
t.Errorf("error unmarshalling mapping: %v", err)
return
}
// open new index
if !*keepIndex {
defer func() {
err := os.RemoveAll("test.bleve")
if err != nil {
t.Fatal(err)
}
}()
}
index, err := bleve.New("test.bleve", &mapping)
if err != nil {
t.Errorf("error creating new index: %v", err)
return
}
defer func() {
err := index.Close()
if err != nil {
t.Fatal(err)
}
}()
// index data
fis, err := ioutil.ReadDir(dir + string(filepath.Separator) + "data")
if err != nil {
t.Errorf("error reading data dir: %v", err)
return
}
for _, fi := range fis {
fileBytes, err := ioutil.ReadFile(dir + string(filepath.Separator) + "data" + string(filepath.Separator) + fi.Name())
if err != nil {
t.Errorf("error reading data file: %v", err)
return
}
filename := fi.Name()
ext := filepath.Ext(filename)
id := filename[0 : len(filename)-len(ext)]
err = index.Index(id, fileBytes)
if err != nil {
t.Errorf("error indexing data: %v", err)
return
}
}
// read the searches
searchBytes, err := ioutil.ReadFile(dir + string(filepath.Separator) + "searches.json")
if err != nil {
t.Errorf("error reading searches: %v", err)
return
}
var searches SearchTests
err = json.Unmarshal(searchBytes, &searches)
if err != nil {
t.Errorf("error unmarshalling searches: %v", err)
return
}
// run the searches
for testNum, search := range searches {
res, err := index.Search(search.Search)
if err != nil {
t.Errorf("error running search: %v", err)
}
if res.Total != search.Result.Total {
t.Errorf("test %d - expected total: %d got %d", testNum, search.Result.Total, res.Total)
continue
}
if len(res.Hits) != len(search.Result.Hits) {
t.Errorf("test %d - expected hits len: %d got %d", testNum, len(search.Result.Hits), len(res.Hits))
continue
}
for hi, hit := range search.Result.Hits {
if hit.ID != res.Hits[hi].ID {
t.Errorf("test %d - expected hit %d to have ID %s got %s", testNum, hi, hit.ID, res.Hits[hi].ID)
}
if hit.Fields != nil {
if !reflect.DeepEqual(hit.Fields, res.Hits[hi].Fields) {
t.Errorf("test %d - expected hit %d to have fields %#v got %#v", testNum, hi, hit.Fields, res.Hits[hi].Fields)
}
}
if hit.Fragments != nil {
if !reflect.DeepEqual(hit.Fragments, res.Hits[hi].Fragments) {
t.Errorf("test %d - expected hit %d to have fragments %#v got %#v", testNum, hi, hit.Fragments, res.Hits[hi].Fragments)
}
}
}
if search.Result.Facets != nil {
if !reflect.DeepEqual(search.Result.Facets, res.Facets) {
t.Errorf("test %d - expected facets: %#v got %#v", testNum, search.Result.Facets, res.Facets)
}
}
}
}

View file

@ -0,0 +1,7 @@
{
"id": "a",
"name": "marty",
"age": 19,
"title": "mista",
"tags": ["gopher", "belieber"]
}

View file

@ -0,0 +1,7 @@
{
"id": "b",
"name": "steve has a long name",
"age": 27,
"birthday": "2001-09-09T01:46:40Z",
"title": "missess"
}

View file

@ -0,0 +1,7 @@
{
"id": "c",
"name": "bob walks home",
"age": 64,
"birthday": "2014-05-13T16:53:20Z",
"title": "masta"
}

View file

@ -0,0 +1,7 @@
{
"id": "d",
"name": "bobbleheaded wings top the phone",
"age": 72,
"birthday": "2014-05-13T16:53:20Z",
"title": "mizz"
}

View file

@ -0,0 +1,27 @@
{
"types": {
"person": {
"properties": {
"name": {
"fields": [
{
"include_term_vectors": true,
"include_in_all": true,
"index": true,
"store": true,
"analyzer": "en",
"type": "text"
}
],
"dynamic": true,
"enabled": true
},
"id": {
"dynamic": false,
"enabled": false
}
}
}
},
"default_type": "person"
}

View file

@ -0,0 +1,406 @@
[
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"term": "marti"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"term": "noone"
}
},
"result": {
"total_hits": 0,
"hits": []
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"match_phrase": "long name"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"term": "walking"
}
},
"result": {
"total_hits": 0,
"hits": []
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"fuzziness": 0,
"prefix_length": 0,
"field": "name",
"match": "walking"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "c"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"prefix": "bobble"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "d"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"query": "+name:phone"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "d"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "age",
"max": 30
}
},
"result": {
"total_hits": 2,
"hits": [
{
"id": "b"
},
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "age",
"max": 30,
"min": 20
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"conjuncts": [
{
"boost": 1,
"field": "age",
"min": 20
},
{
"boost": 1,
"field": "age",
"max": 30
}
]
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "birthday",
"start": "2010-01-01"
}
},
"result": {
"total_hits": 2,
"hits": [
{
"id": "d"
},
{
"id": "c"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "birthday",
"end": "2010-01-01"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "tags",
"term": "gopher"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "tags",
"term": "belieber"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "tags",
"term": "notintagsarray"
}
},
"result": {
"total_hits": 0,
"hits": []
}
},
{
"comment": "with size 0, total should be 1, but hits empty",
"search": {
"from": 0,
"size": 0,
"query": {
"field": "name",
"term": "marti"
}
},
"result": {
"total_hits": 1,
"hits": []
}
},
{
"comment": "a search for doc a that includes tags field, verifies both values come back",
"search": {
"from": 0,
"size": 10,
"fields": ["tags"],
"query": {
"field": "name",
"term": "marti"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a",
"fields": {
"tags": ["gopher", "belieber"]
}
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"term": "msrti",
"fuzziness": 1
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"comment": "highlight results",
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"match": "long"
},
"highlight": {
"fields": ["name"]
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b",
"fragments": {
"name": ["steve has a <span class=\"highlight\">long</span> name"]
}
}
]
}
},
{
"comment": "highlight results without specifying fields",
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"match": "long"
},
"highlight": {}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b",
"fragments": {
"name": ["steve has a <span class=\"highlight\">long</span> name"]
}
}
]
}
},
{
"comment": "request fields",
"search": {
"from": 0,
"size": 10,
"fields": ["age","birthday"],
"query": {
"field": "name",
"match": "long"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b",
"fields": {
"age": 27,
"birthday": "2001-09-09T01:46:40Z"
}
}
]
}
}
]

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "book",
"rating": 2,
"updated": "2014-11-25"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "book",
"rating": 7,
"updated": "2013-07-25"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "book",
"rating": 1,
"updated": "2014-03-03"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "book",
"rating": 9,
"updated": "2014-09-16"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "book",
"rating": 5,
"updated": "2014-11-15"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "movie",
"rating": 3,
"updated": "2017-06-05"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "movie",
"rating": 9,
"updated": "2011-10-03"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "movie",
"rating": 9,
"updated": "2019-08-26"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "movie",
"rating": 1,
"updated": "2014-12-14"
}

View file

@ -0,0 +1,6 @@
{
"category": "inventory",
"type": "game",
"rating": 9,
"updated": "2013-10-20"
}

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1,144 @@
[
{
"search": {
"from": 0,
"size": 0,
"query": {
"field": "category",
"term": "inventory"
},
"facets": {
"types": {
"size": 3,
"field": "type"
}
}
},
"result": {
"total_hits": 10,
"hits": [],
"facets": {
"types": {
"field": "type",
"total": 10,
"missing": 0,
"other": 0,
"terms": [
{
"term": "book",
"count": 5
},
{
"term": "movie",
"count": 4
},
{
"term": "game",
"count": 1
}
]
}
}
}
},
{
"search": {
"from": 0,
"size": 0,
"query": {
"field": "category",
"term": "inventory"
},
"facets": {
"types": {
"size": 3,
"field": "rating",
"numeric_ranges": [
{
"name": "low",
"max": 5
},
{
"name": "high",
"min": 5
}
]
}
}
},
"result": {
"total_hits": 10,
"hits": [],
"facets": {
"types": {
"field": "rating",
"total": 10,
"missing": 0,
"other": 0,
"numeric_ranges": [
{
"name": "high",
"count": 6,
"min": 5
},
{
"name": "low",
"count": 4,
"max": 5
}
]
}
}
}
},
{
"search": {
"from": 0,
"size": 0,
"query": {
"field": "category",
"term": "inventory"
},
"facets": {
"types": {
"size": 3,
"field": "updated",
"date_ranges": [
{
"name": "old",
"end": "2012-01-01"
},
{
"name": "new",
"start": "2012-01-01"
}
]
}
}
},
"result": {
"total_hits": 10,
"hits": [],
"facets": {
"types": {
"field": "updated",
"total": 10,
"missing": 0,
"other": 0,
"date_ranges": [
{
"name": "new",
"count": 9,
"start": "2012-01-01T00:00:00Z"
},
{
"name": "old",
"count": 1,
"end": "2012-01-01T00:00:00Z"
}
]
}
}
}
}
]

View file

@ -0,0 +1,4 @@
{
"description": "From Prolog to Erlang to Haskell to Lisp to TLC and then back to Prolog I have journeyed, and I'd like to share some of the beautiful",
"category": "Word"
}

View file

@ -0,0 +1,4 @@
{
"description": "different cats",
"category": "Perl"
}

View file

@ -0,0 +1,4 @@
{
"description": "many cats",
"category": "Perl"
}

View file

@ -0,0 +1,4 @@
{
"description": "From Prolog to Erlang to Haskell to Lisp to TLC and then back to Prolog I have journeyed, and I'd like to share some of the beautiful",
"category": "Perl"
}

View file

@ -0,0 +1,4 @@
{
"description": "From Prolog to Erlang to Haskell to Gel to TLC and then back to Prolog I have journeyed, and I'd like to share some of the beautiful",
"category": "Perl"
}

View file

@ -0,0 +1,76 @@
{
"default_mapping": {
"enabled": true,
"dynamic": true,
"properties": {
"category": {
"enabled": true,
"dynamic": true,
"fields": [
{
"type": "text",
"analyzer": "keyword",
"store": true,
"index": true,
"include_term_vectors": true,
"include_in_all": true
}
],
"default_analyzer": ""
},
"description": {
"enabled": true,
"dynamic": true,
"fields": [
{
"type": "text",
"analyzer": "en",
"store": true,
"index": true,
"include_term_vectors": true,
"include_in_all": true
}
],
"default_analyzer": ""
},
"summary": {
"enabled": true,
"dynamic": true,
"fields": [
{
"type": "text",
"analyzer": "en",
"store": true,
"index": true,
"include_term_vectors": true,
"include_in_all": true
}
],
"default_analyzer": ""
},
"url": {
"enabled": true,
"dynamic": true,
"fields": [
{
"type": "text",
"analyzer": "keyword",
"store": true,
"index": true,
"include_term_vectors": true,
"include_in_all": true
}
],
"default_analyzer": ""
}
},
"default_analyzer": ""
},
"type_field": "_type",
"default_type": "_default",
"default_analyzer": "en",
"default_datetime_parser": "dateTimeOptional",
"default_field": "_all",
"byte_array_converter": "json",
"analysis": {}
}

View file

@ -0,0 +1,105 @@
[
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "category",
"match_phrase": "Perl"
}
},
"result": {
"total_hits": 4,
"hits": [
{
"id": "3507@FOSDEM15@fosdem.org"
},
{
"id": "3505@FOSDEM15@fosdem.org"
},
{
"id": "3496@FOSDEM15@fosdem.org"
}
,
{
"id": "3492@FOSDEM15@fosdem.org"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"match": "lisp"
}
},
"result": {
"total_hits": 2,
"hits": [
{
"id": "3505@FOSDEM15@fosdem.org"
},
{
"id": "3311@FOSDEM15@fosdem.org"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {"boost":1,"query":"+lisp +category:Perl"}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "3505@FOSDEM15@fosdem.org"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {"boost":1,"query":"+lisp +category:\"Perl\""}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "3505@FOSDEM15@fosdem.org"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"must": {
"conjuncts":[
{"boost":1,"query":"+cats"},
{"field":"category","match_phrase":"Perl"}
]
}
}
},
"result": {
"total_hits": 2,
"hits": [
{
"id": "3496@FOSDEM15@fosdem.org"
},
{
"id": "3492@FOSDEM15@fosdem.org"
}
]
}
}
]

View file

@ -0,0 +1,3 @@
{
"body": "Twenty Thousand Leagues Under The Sea"
}

View file

@ -0,0 +1,23 @@
{
"types": {
"book": {
"properties": {
"body": {
"fields": [
{
"include_term_vectors": true,
"include_in_all": true,
"index": true,
"store": true,
"analyzer": "en",
"type": "text"
}
],
"dynamic": true,
"enabled": true
}
}
}
},
"default_type": "book"
}

View file

@ -0,0 +1,326 @@
[
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Twenty"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Twenty Thousand"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Twenty Thousand Leagues"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Twenty Thousand Leagues Under"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Twenty Thousand Leagues Under the"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Twenty Thousand Leagues Under the Sea"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Thousand"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Thousand Leagues"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Thousand Leagues Under"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Thousand Leagues Under the"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Thousand Leagues Under the Sea"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Leagues"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Leagues Under"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Leagues Under the"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Leagues Under the Sea"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Under the Sea"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "the Sea"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
},
{
"search": {
"from": 0,
"size": 10,
"query": {
"field": "body",
"match_phrase": "Sea"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "a"
}
]
}
}
]