Abacn commented on a change in pull request #17173:
URL: https://github.com/apache/beam/pull/17173#discussion_r836586379
##########
File path: sdks/go/pkg/beam/io/datastoreio/datastore_test.go
##########
@@ -16,11 +16,164 @@
package datastoreio
import (
+ "context"
+ "errors"
+ "reflect"
+ "strings"
"testing"
"cloud.google.com/go/datastore"
+ "github.com/apache/beam/sdks/v2/go/pkg/beam"
+ "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime"
+ "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/ptest"
+ "google.golang.org/api/option"
)
+// fake client type implements datastoreio.clientType
+type fakeClient struct {
+ runFn func()
+ closeFn func()
+}
+
+func (client *fakeClient) Run(context.Context, *datastore.Query)
*datastore.Iterator {
+ client.runFn()
+ // return an empty iterator
+ return new(datastore.Iterator)
+}
+
+func (client *fakeClient) Close() error {
+ client.closeFn()
+ return nil
+}
+
+// mock type for query
+type Foo struct {
+}
+
+type Bar struct {
+}
+
+func TestRead(t *testing.T) {
+ runCounter := 0
+ closeCounter := 0
+
+ // setup a fake newClient caller
+ originalClient := newClient
+ newClient = func(ctx context.Context,
+ projectID string,
+ opts ...option.ClientOption) (clientType, error) {
+ client := fakeClient{
+ runFn: func() {
+ runCounter += 1
+ },
+ closeFn: func() {
+ closeCounter += 1
+ },
+ }
+ return &client, nil
+ }
Review comment:
Consolidated test cases
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]