From e882659a519645e7b538b82ff22049d35d016d0c Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Tue, 6 Dec 2016 10:26:10 -0500 Subject: [PATCH] bigquery: fix integration test Since Table.Read can return rows in any order, sort results in the UploadAndReadStructs test. Change-Id: I1d3fc80ed8a6887a22f88ba0028352c7e7c02f73 Reviewed-on: https://code-review.googlesource.com/9722 Reviewed-by: Sai Cheemalapati --- bigquery/integration_test.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bigquery/integration_test.go b/bigquery/integration_test.go index f83f95ed6375..8a3ed79c5f6a 100644 --- a/bigquery/integration_test.go +++ b/bigquery/integration_test.go @@ -326,17 +326,30 @@ func TestIntegration_UploadAndReadStructs(t *testing.T) { // Test iteration with structs. it := table.Read(ctx) - for i, want := range scores { - var got score - if err := it.Next(&got); err != nil { - t.Fatal(err) + var got []score + for { + var g score + err := it.Next(&g) + if err == iterator.Done { + break } - if got != want { - t.Errorf("%d: got %+v, want %+v", i, got, want) + if err != nil { + t.Fatal(err) } + got = append(got, g) + } + sort.Sort(byName(got)) + if !reflect.DeepEqual(got, scores) { + t.Errorf("got %+v, want %+v", got, scores) } } +type byName []score + +func (b byName) Len() int { return len(b) } +func (b byName) Swap(i, j int) { b[i], b[j] = b[j], b[i] } +func (b byName) Less(i, j int) bool { return b[i].Name < b[j].Name } + func TestIntegration_Update(t *testing.T) { if client == nil { t.Skip("Integration tests skipped")