[
https://issues.apache.org/jira/browse/BEAM-13918?focusedWorklogId=748728&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-748728
]
ASF GitHub Bot logged work on BEAM-13918:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 28/Mar/22 15:53
Start Date: 28/Mar/22 15:53
Worklog Time Spent: 10m
Work Description: Abacn commented on a change in pull request #17173:
URL: https://github.com/apache/beam/pull/17173#discussion_r836586135
##########
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
+ }
+
+ testCases := []struct {
+ v interface{}
+ shard int
+ expectRun int
+ expectClose int
+ }{
+ // case 1: shard=1, without split query
+ {Foo{}, 1, 1, 1},
+ // case 2: shard=2 (>1), with split query
+ {Bar{}, 2, 2, 2},
+ }
+ for _, tc := range testCases {
+ itemType := reflect.TypeOf(tc.v)
+ itemKey := runtime.RegisterType(itemType)
+
+ p, s := beam.NewPipelineWithRoot()
+ Read(s, "project", "Item", tc.shard, itemType, itemKey)
+
+ ptest.RunAndValidate(t, p)
+
+ if runCounter != tc.expectRun {
+ t.Errorf("got number of datastore.Client.Run call: %v,
wanted %v",
+ runCounter, tc.expectRun)
+ }
+ if runCounter != tc.expectRun {
+ t.Errorf("got number of datastore.Client.Run call: %v,
wanted %v",
+ closeCounter, tc.expectClose)
+ }
+
+ // reset counter
+ runCounter = 0
+ closeCounter = 0
+ }
+
+ // tear down: recover original newClient caller
+ newClient = originalClient
Review comment:
Adapted the function field approach in the last comment. Cleanup no
longer needed
--
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 748728)
Time Spent: 2h (was: 1h 50m)
> Increase unit testing coverage in the datastoreio package
> ---------------------------------------------------------
>
> Key: BEAM-13918
> URL: https://issues.apache.org/jira/browse/BEAM-13918
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-go
> Reporter: Jack McCluskey
> Assignee: Yi Hu
> Priority: P2
> Time Spent: 2h
> Remaining Estimate: 0h
>
> Increase unit testing coverage in the [datastoreio
> package|https://github.com/apache/beam/tree/release-2.36.0/sdks/go/pkg/beam/io/datastoreio]
> We want code coverage at or above 50%, it is currently at 17.2%.
> This will involve mocking a datastore service.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)