vendor: update all dependencies
* Update all dependencies * Remove all `[[constraint]]` from Gopkg.toml * Add in the minimum number of `[[override]]` to build * Remove go get of github.com/inconshreveable/mousetrap as it is vendored * Update docs with new policy on constraints
This commit is contained in:
+171
-5
@@ -15,6 +15,8 @@
|
||||
package firestore
|
||||
|
||||
import (
|
||||
"math"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
@@ -22,9 +24,58 @@ import (
|
||||
"cloud.google.com/go/internal/pretty"
|
||||
pb "google.golang.org/genproto/googleapis/firestore/v1beta1"
|
||||
|
||||
tspb "github.com/golang/protobuf/ptypes/timestamp"
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
)
|
||||
|
||||
func TestFilterToProto(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
in filter
|
||||
want *pb.StructuredQuery_Filter
|
||||
}{
|
||||
{
|
||||
filter{[]string{"a"}, ">", 1},
|
||||
&pb.StructuredQuery_Filter{FilterType: &pb.StructuredQuery_Filter_FieldFilter{
|
||||
FieldFilter: &pb.StructuredQuery_FieldFilter{
|
||||
Field: &pb.StructuredQuery_FieldReference{FieldPath: "a"},
|
||||
Op: pb.StructuredQuery_FieldFilter_GREATER_THAN,
|
||||
Value: intval(1),
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
filter{[]string{"a"}, "==", nil},
|
||||
&pb.StructuredQuery_Filter{FilterType: &pb.StructuredQuery_Filter_UnaryFilter{
|
||||
UnaryFilter: &pb.StructuredQuery_UnaryFilter{
|
||||
OperandType: &pb.StructuredQuery_UnaryFilter_Field{
|
||||
Field: &pb.StructuredQuery_FieldReference{FieldPath: "a"},
|
||||
},
|
||||
Op: pb.StructuredQuery_UnaryFilter_IS_NULL,
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
filter{[]string{"a"}, "==", math.NaN()},
|
||||
&pb.StructuredQuery_Filter{FilterType: &pb.StructuredQuery_Filter_UnaryFilter{
|
||||
UnaryFilter: &pb.StructuredQuery_UnaryFilter{
|
||||
OperandType: &pb.StructuredQuery_UnaryFilter_Field{
|
||||
Field: &pb.StructuredQuery_FieldReference{FieldPath: "a"},
|
||||
},
|
||||
Op: pb.StructuredQuery_UnaryFilter_IS_NAN,
|
||||
},
|
||||
}},
|
||||
},
|
||||
} {
|
||||
got, err := test.in.toProto()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !testEqual(got, test.want) {
|
||||
t.Errorf("%+v:\ngot\n%v\nwant\n%v", test.in, pretty.Value(got), pretty.Value(test.want))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryToProto(t *testing.T) {
|
||||
filtr := func(path []string, op string, val interface{}) *pb.StructuredQuery_Filter {
|
||||
f, err := filter{path, op, val}.toProto()
|
||||
@@ -88,10 +139,15 @@ func TestQueryToProto(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: ` q.Where("a", ">", 5)`,
|
||||
desc: `q.Where("a", ">", 5)`,
|
||||
in: q.Where("a", ">", 5),
|
||||
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, ">", 5)},
|
||||
},
|
||||
{
|
||||
desc: `q.Where("a", "==", NaN)`,
|
||||
in: q.Where("a", "==", float32(math.NaN())),
|
||||
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "==", math.NaN())},
|
||||
},
|
||||
{
|
||||
desc: `q.Where("a", ">", 5).Where("b", "<", "foo")`,
|
||||
in: q.Where("a", ">", 5).Where("b", "<", "foo"),
|
||||
@@ -524,10 +580,10 @@ func TestQueryGetAll(t *testing.T) {
|
||||
Fields: map[string]*pb.Value{"f": intval(1)},
|
||||
},
|
||||
}
|
||||
|
||||
wantReadTimes := []*tspb.Timestamp{aTimestamp, aTimestamp2}
|
||||
srv.addRPC(nil, []interface{}{
|
||||
&pb.RunQueryResponse{Document: wantPBDocs[0]},
|
||||
&pb.RunQueryResponse{Document: wantPBDocs[1]},
|
||||
&pb.RunQueryResponse{Document: wantPBDocs[0], ReadTime: aTimestamp},
|
||||
&pb.RunQueryResponse{Document: wantPBDocs[1], ReadTime: aTimestamp2},
|
||||
})
|
||||
gotDocs, err := c.Collection("C").Documents(ctx).GetAll()
|
||||
if err != nil {
|
||||
@@ -537,7 +593,7 @@ func TestQueryGetAll(t *testing.T) {
|
||||
t.Errorf("got %d docs, wanted %d", got, want)
|
||||
}
|
||||
for i, got := range gotDocs {
|
||||
want, err := newDocumentSnapshot(c.Doc(docNames[i]), wantPBDocs[i], c)
|
||||
want, err := newDocumentSnapshot(c.Doc(docNames[i]), wantPBDocs[i], c, wantReadTimes[i])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -549,3 +605,113 @@ func TestQueryGetAll(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryCompareFunc(t *testing.T) {
|
||||
mv := func(fields ...interface{}) map[string]*pb.Value {
|
||||
m := map[string]*pb.Value{}
|
||||
for i := 0; i < len(fields); i += 2 {
|
||||
m[fields[i].(string)] = fields[i+1].(*pb.Value)
|
||||
}
|
||||
return m
|
||||
}
|
||||
snap := func(ref *DocumentRef, fields map[string]*pb.Value) *DocumentSnapshot {
|
||||
return &DocumentSnapshot{Ref: ref, proto: &pb.Document{Fields: fields}}
|
||||
}
|
||||
|
||||
c := &Client{}
|
||||
coll := c.Collection("C")
|
||||
doc1 := coll.Doc("doc1")
|
||||
doc2 := coll.Doc("doc2")
|
||||
doc3 := coll.Doc("doc3")
|
||||
doc4 := coll.Doc("doc4")
|
||||
for _, test := range []struct {
|
||||
q Query
|
||||
in []*DocumentSnapshot
|
||||
want []*DocumentSnapshot
|
||||
}{
|
||||
{
|
||||
q: coll.OrderBy("foo", Asc),
|
||||
in: []*DocumentSnapshot{
|
||||
snap(doc3, mv("foo", intval(2))),
|
||||
snap(doc4, mv("foo", intval(1))),
|
||||
snap(doc2, mv("foo", intval(2))),
|
||||
},
|
||||
want: []*DocumentSnapshot{
|
||||
snap(doc4, mv("foo", intval(1))),
|
||||
snap(doc2, mv("foo", intval(2))),
|
||||
snap(doc3, mv("foo", intval(2))),
|
||||
},
|
||||
},
|
||||
{
|
||||
q: coll.OrderBy("foo", Desc),
|
||||
in: []*DocumentSnapshot{
|
||||
snap(doc3, mv("foo", intval(2))),
|
||||
snap(doc4, mv("foo", intval(1))),
|
||||
snap(doc2, mv("foo", intval(2))),
|
||||
},
|
||||
want: []*DocumentSnapshot{
|
||||
snap(doc3, mv("foo", intval(2))),
|
||||
snap(doc2, mv("foo", intval(2))),
|
||||
snap(doc4, mv("foo", intval(1))),
|
||||
},
|
||||
},
|
||||
{
|
||||
q: coll.OrderBy("foo.bar", Asc),
|
||||
in: []*DocumentSnapshot{
|
||||
snap(doc1, mv("foo", mapval(mv("bar", intval(1))))),
|
||||
snap(doc2, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
snap(doc3, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
},
|
||||
want: []*DocumentSnapshot{
|
||||
snap(doc1, mv("foo", mapval(mv("bar", intval(1))))),
|
||||
snap(doc2, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
snap(doc3, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
},
|
||||
},
|
||||
{
|
||||
q: coll.OrderBy("foo.bar", Desc),
|
||||
in: []*DocumentSnapshot{
|
||||
snap(doc1, mv("foo", mapval(mv("bar", intval(1))))),
|
||||
snap(doc2, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
snap(doc3, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
},
|
||||
want: []*DocumentSnapshot{
|
||||
snap(doc3, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
snap(doc2, mv("foo", mapval(mv("bar", intval(2))))),
|
||||
snap(doc1, mv("foo", mapval(mv("bar", intval(1))))),
|
||||
},
|
||||
},
|
||||
} {
|
||||
got := append([]*DocumentSnapshot(nil), test.in...)
|
||||
sort.Sort(byQuery{test.q.compareFunc(), got})
|
||||
if diff := testDiff(got, test.want); diff != "" {
|
||||
t.Errorf("%+v: %s", test.q, diff)
|
||||
}
|
||||
}
|
||||
|
||||
// Want error on missing field.
|
||||
q := coll.OrderBy("bar", Asc)
|
||||
if q.err != nil {
|
||||
t.Fatalf("bad query: %v", q.err)
|
||||
}
|
||||
cf := q.compareFunc()
|
||||
s := snap(doc1, mv("foo", intval(1)))
|
||||
if _, err := cf(s, s); err == nil {
|
||||
t.Error("got nil, want error")
|
||||
}
|
||||
}
|
||||
|
||||
type byQuery struct {
|
||||
compare func(d1, d2 *DocumentSnapshot) (int, error)
|
||||
docs []*DocumentSnapshot
|
||||
}
|
||||
|
||||
func (b byQuery) Len() int { return len(b.docs) }
|
||||
func (b byQuery) Swap(i, j int) { b.docs[i], b.docs[j] = b.docs[j], b.docs[i] }
|
||||
func (b byQuery) Less(i, j int) bool {
|
||||
c, err := b.compare(b.docs[i], b.docs[j])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return c < 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user