From 4b0a86cb0dd2edb64dc06d6b2a00273535eb4508 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 12 Aug 2014 11:04:32 +0200 Subject: [PATCH 1/3] documentation fixes --- query_transformation.go | 2 +- results.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/query_transformation.go b/query_transformation.go index fff5b1ce..c3e17fcf 100644 --- a/query_transformation.go +++ b/query_transformation.go @@ -34,7 +34,7 @@ func (o *OrderByOpts) toMap() map[string]interface{} { // Sort the sequence by document values of the given key(s). // To specify the index to use for ordering us a last argument in the following form: // -// map[string]interface{}{"index": "index-name"} +// OrderByOpts{Index: "index-name"} // // OrderBy defaults to ascending ordering. To explicitly specify the ordering, // wrap the attribute with either Asc or Desc. diff --git a/results.go b/results.go index d8508d65..0075b0ca 100644 --- a/results.go +++ b/results.go @@ -196,7 +196,7 @@ func (c *Cursor) All(result interface{}) error { return c.Close() } -// All retrieves a single document from the result set into the provided +// One retrieves a single document from the result set into the provided // slice and closes the cursor. func (c *Cursor) One(result interface{}) error { ok := c.Next(result) From 7e2df5c1c96958017bd98cdcc6aabaa9dd7f697a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 12 Aug 2014 11:13:50 +0200 Subject: [PATCH 2/3] Use gopkg.in/check.v1 instead of launchpad.net/gocheck gocheck package moved to github and should be referenced as gopkg.in/check.v1 https://github.com/go-check/check Update wercker to use gopkg.in/check.v1 --- gorethink_test.go | 2 +- query_aggregation_test.go | 2 +- query_control_test.go | 2 +- query_db_test.go | 2 +- query_join_test.go | 2 +- query_manipulation_test.go | 2 +- query_math_test.go | 2 +- query_select_test.go | 2 +- query_string_test.go | 2 +- query_table_test.go | 2 +- query_test.go | 2 +- query_time_test.go | 2 +- query_transformation_test.go | 2 +- query_write_test.go | 2 +- results_test.go | 2 +- session_test.go | 2 +- wercker.yml | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gorethink_test.go b/gorethink_test.go index 755a20a8..71bd8c05 100644 --- a/gorethink_test.go +++ b/gorethink_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) var sess *Session diff --git a/query_aggregation_test.go b/query_aggregation_test.go index e5d42f1b..1b3bc540 100644 --- a/query_aggregation_test.go +++ b/query_aggregation_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestAggregationReduce(c *test.C) { diff --git a/query_control_test.go b/query_control_test.go index 56be6f0f..7386989b 100644 --- a/query_control_test.go +++ b/query_control_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestControlExecNil(c *test.C) { diff --git a/query_db_test.go b/query_db_test.go index 3ff1de9e..efca06c5 100644 --- a/query_db_test.go +++ b/query_db_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestDbCreate(c *test.C) { diff --git a/query_join_test.go b/query_join_test.go index 5f385648..e11ad4fc 100644 --- a/query_join_test.go +++ b/query_join_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestJoinInnerJoin(c *test.C) { diff --git a/query_manipulation_test.go b/query_manipulation_test.go index bd7d0d90..8a580bb3 100644 --- a/query_manipulation_test.go +++ b/query_manipulation_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestManipulationDocField(c *test.C) { diff --git a/query_math_test.go b/query_math_test.go index cfd885b8..0b9945cb 100644 --- a/query_math_test.go +++ b/query_math_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestMathAdd(c *test.C) { diff --git a/query_select_test.go b/query_select_test.go index bac523bf..e7f4fe30 100644 --- a/query_select_test.go +++ b/query_select_test.go @@ -3,7 +3,7 @@ package gorethink import ( "fmt" - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestSelectGet(c *test.C) { diff --git a/query_string_test.go b/query_string_test.go index 5fc32af1..a11e7967 100644 --- a/query_string_test.go +++ b/query_string_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestStringMatchSuccess(c *test.C) { diff --git a/query_table_test.go b/query_table_test.go index 543eae36..6ec94cce 100644 --- a/query_table_test.go +++ b/query_table_test.go @@ -3,7 +3,7 @@ package gorethink import ( "sync" - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestTableCreate(c *test.C) { diff --git a/query_test.go b/query_test.go index 2cd9cdae..938b74da 100644 --- a/query_test.go +++ b/query_test.go @@ -1,6 +1,6 @@ package gorethink -import test "launchpad.net/gocheck" +import test "gopkg.in/check.v1" func (s *RethinkSuite) TestQueryRun(c *test.C) { var response string diff --git a/query_time_test.go b/query_time_test.go index 2f301d65..3ee39c0a 100644 --- a/query_time_test.go +++ b/query_time_test.go @@ -3,7 +3,7 @@ package gorethink import ( "time" - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestTimeTime(c *test.C) { diff --git a/query_transformation_test.go b/query_transformation_test.go index c2317f9a..9001918a 100644 --- a/query_transformation_test.go +++ b/query_transformation_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestTransformationMapImplicit(c *test.C) { diff --git a/query_write_test.go b/query_write_test.go index 91f6041f..abe96a73 100644 --- a/query_write_test.go +++ b/query_write_test.go @@ -1,7 +1,7 @@ package gorethink import ( - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestWriteInsert(c *test.C) { diff --git a/results_test.go b/results_test.go index 82798162..be5a77ba 100644 --- a/results_test.go +++ b/results_test.go @@ -1,6 +1,6 @@ package gorethink -import test "launchpad.net/gocheck" +import test "gopkg.in/check.v1" type object struct { Id int64 `gorethink:"id,omitempty"` diff --git a/session_test.go b/session_test.go index 7f944c54..4ee9dcfa 100644 --- a/session_test.go +++ b/session_test.go @@ -3,7 +3,7 @@ package gorethink import ( "os" - test "launchpad.net/gocheck" + test "gopkg.in/check.v1" ) func (s *RethinkSuite) TestSessionConnect(c *test.C) { diff --git a/wercker.yml b/wercker.yml index 5edf5906..bf0c83e1 100644 --- a/wercker.yml +++ b/wercker.yml @@ -16,7 +16,7 @@ build: code: | cd $WERCKER_SOURCE_DIR go version - go get ./... && go get -u launchpad.net/gocheck && go test -i + go get ./... && go get -u gopkg.in/check.v1 && go test -i # Build the project - script: From 7c69abf77513b93130a97c8827f785b136b29a0a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 12 Aug 2014 11:17:42 +0200 Subject: [PATCH 3/3] `cursor.One` should work without checking `IsNil` on a user side. `cursor.One` is a higher level funcion to get a single element from the result set. It already returns `ErrEmptyResult`, so to be consistent with a function responsibility it should also return that error even when user didn't check `IsNil` before performing `One`. --- query_control_test.go | 2 +- results.go | 3 +++ results_test.go | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/query_control_test.go b/query_control_test.go index 7386989b..d50fc03f 100644 --- a/query_control_test.go +++ b/query_control_test.go @@ -15,7 +15,7 @@ func (s *RethinkSuite) TestControlExecNil(c *test.C) { err = res.One(&response) - c.Assert(err, test.IsNil) + c.Assert(err, test.Equals, ErrEmptyResult) c.Assert(response, test.Equals, nil) } diff --git a/results.go b/results.go index 0075b0ca..c329a9af 100644 --- a/results.go +++ b/results.go @@ -199,6 +199,9 @@ func (c *Cursor) All(result interface{}) error { // One retrieves a single document from the result set into the provided // slice and closes the cursor. func (c *Cursor) One(result interface{}) error { + if c.IsNil() { + return ErrEmptyResult + } ok := c.Next(result) if !ok { err := c.Err() diff --git a/results_test.go b/results_test.go index be5a77ba..982563e8 100644 --- a/results_test.go +++ b/results_test.go @@ -163,7 +163,8 @@ func (s *RethinkSuite) TestEmptyResults(c *test.C) { res, err = Db("test").Table("test").Get("missing value").Run(sess) c.Assert(err, test.IsNil) var response interface{} - res.One(&response) + err = res.One(&response) + c.Assert(err, test.Equals, ErrEmptyResult) c.Assert(res.IsNil(), test.Equals, true) res, err = Db("test").Table("test").Get("missing value").Run(sess)