[datastore] return nil from CurrentTransaction

Fix instance of https://golang.org/doc/faq#nil_error in
impl/cloud.

Change-Id: I5547c323c79b98b8e59eb6967e485a7aed26bd55
Reviewed-on: https://chromium-review.googlesource.com/826505
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Daniel Jacques <dnj@chromium.org>
diff --git a/impl/cloud/datastore.go b/impl/cloud/datastore.go
index f4be9b3..b6596fa 100644
--- a/impl/cloud/datastore.go
+++ b/impl/cloud/datastore.go
@@ -273,7 +273,12 @@
 	return withDatastoreTransaction(bds, nil)
 }
 
-func (bds *boundDatastore) CurrentTransaction() ds.Transaction { return bds.transaction }
+func (bds *boundDatastore) CurrentTransaction() ds.Transaction {
+	if bds.transaction == nil {
+		return nil
+	}
+	return bds.transaction
+}
 
 func (bds *boundDatastore) Constraints() ds.Constraints { return constraints.DS() }
 
diff --git a/impl/cloud/datastore_test.go b/impl/cloud/datastore_test.go
index 3dad4a3..1c580b1 100644
--- a/impl/cloud/datastore_test.go
+++ b/impl/cloud/datastore_test.go
@@ -54,6 +54,16 @@
 func mkp(vals ...interface{}) ds.PropertyData   { return mkProperties(true, false, vals...) }
 func mkpNI(vals ...interface{}) ds.PropertyData { return mkProperties(false, false, vals...) }
 
+// shouldBeUntypedNil asserts that actual is nil, with a nil type pointer
+// For example: https://play.golang.org/p/qN25iAYQw5Z
+func shouldBeUntypedNil(actual interface{}, _ ...interface{}) string {
+	if actual == nil {
+		return ""
+	}
+	return fmt.Sprintf(`Expected: (%T, %v)
+Actual:   (%T, %v)`, nil, nil, actual, actual)
+}
+
 // TestDatastore tests the cloud datastore implementation.
 //
 // This test uses the gcloud datastore emulator. Like the Go datastore package,
@@ -92,7 +102,7 @@
 		testTime := ds.RoundTime(time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC))
 		_ = testTime
 
-		cfg := Config{DS: client}
+		cfg := Config{ProjectID: "luci-gae-test", DS: client}
 		c = cfg.Use(c, nil)
 
 		Convey(`Supports namespaces`, func() {
@@ -311,7 +321,7 @@
 					So(err, ShouldEqual, testError)
 
 					// Confirm that noTxnPM was added.
-					So(ds.CurrentTransaction(c), ShouldBeNil)
+					So(ds.CurrentTransaction(c), shouldBeUntypedNil)
 					So(ds.Get(c, noTxnPM), ShouldBeNil)
 
 					pmap := ds.PropertyMap{"$kind": mkp("Test"), "$id": mkp("quux")}