[
https://issues.apache.org/jira/browse/BEAM-13910?focusedWorklogId=733063&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-733063
]
ASF GitHub Bot logged work on BEAM-13910:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 25/Feb/22 14:23
Start Date: 25/Feb/22 14:23
Worklog Time Spent: 10m
Work Description: damccorm commented on a change in pull request #16942:
URL: https://github.com/apache/beam/pull/16942#discussion_r814807823
##########
File path: sdks/go/pkg/beam/util/gcsx/gcs_test.go
##########
@@ -13,35 +13,62 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package gcsx_test
+package gcsx
import (
- "context"
- "time"
+ "testing"
- "cloud.google.com/go/storage"
- "github.com/apache/beam/sdks/v2/go/pkg/beam/util/gcsx"
+ "github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors"
)
-func Example() {
- ctx := context.Background()
- c, err := gcsx.NewClient(ctx, storage.ScopeReadOnly)
- if err != nil {
- // do something
+func TestMakeObject(t *testing.T) {
+ if got, want := MakeObject("some-bucket", "some/path"),
"gs://some-bucket/some/path"; got != want {
+ t.Fatalf("MakeObject() Got: %v Want: %v", got, want)
}
+}
- buckets, object, err := gcsx.ParseObject("gs://some-bucket/some-object")
- if err != nil {
- // do something
+func TestParseObject(t *testing.T) {
+ tests := []struct {
+ object string
+ bucket string
+ path string
+ err error
+ }{
+ {
+ object: "gs://some-bucket/some-object",
+ bucket: "some-bucket",
+ path: "some-object",
+ err: nil,
+ },
+ {
+ object: "gs://some-bucket",
+ bucket: "some-bucket",
+ path: "",
+ err: nil,
+ },
+ {
+ object: "gs://",
+ bucket: "",
+ path: "",
+ err: errors.Errorf("object gs:// must have bucket"),
+ },
+ {
+ object: "other://some-bucket/some-object",
+ bucket: "",
+ path: "",
+ err: errors.Errorf("object
other://some-bucket/some-object must have 'gs' scheme"),
+ },
}
- ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
- defer cancel()
-
- bytes, err := gcsx.ReadObject(ctx, c, buckets, object)
- if err != nil {
- // do something
+ for _, test := range tests {
+ if bucket, path, err := ParseObject(test.object); bucket !=
test.bucket || path != test.path || (err != nil && test.err == nil) || (err ==
nil && test.err != nil) {
+ t.Errorf("ParseObject(%v) Got: %v, %v, %v Want: %v, %v,
%v", test.object, bucket, path, err, test.bucket, test.path, test.err)
+ }
}
+}
- _ = bytes
+func TestJoin(t *testing.T) {
+ if got, want := Join("gs://some-bucket/some-object", "some/path",
"more/pathing"), "gs://some-bucket/some-object/some/path/more/pathing"; got !=
want {
+ t.Fatalf("MakeObject() Got: %v Want: %v", got, want)
Review comment:
No gs prefix panics (and also shells out to ParseObject which I'm
already testing), so I'll probably skip that one, I updated with the remaining
suggestions though
--
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: 733063)
Time Spent: 1h 50m (was: 1h 40m)
> Add unit testing to the gcsx package
> ------------------------------------
>
> Key: BEAM-13910
> URL: https://issues.apache.org/jira/browse/BEAM-13910
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-go
> Reporter: Jack McCluskey
> Assignee: Danny McCormick
> Priority: P2
> Labels: starter
> Time Spent: 1h 50m
> Remaining Estimate: 0h
>
> Add unit testing to the [gcsx
> package|https://github.com/apache/beam/tree/release-2.36.0/sdks/go/pkg/beam/util/gcsx]
> We want code coverage at or above 50%, it is currently at 0%.
> Helper functions can be tested easily, main functionality requires mocking
> GCS interactions.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)