[
https://issues.apache.org/jira/browse/BEAM-13904?focusedWorklogId=738564&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-738564
]
ASF GitHub Bot logged work on BEAM-13904:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 09/Mar/22 06:21
Start Date: 09/Mar/22 06:21
Worklog Time Spent: 10m
Work Description: youngoli commented on a change in pull request #17024:
URL: https://github.com/apache/beam/pull/17024#discussion_r822270180
##########
File path: sdks/go/pkg/beam/core/util/reflectx/call_test.go
##########
@@ -0,0 +1,125 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package reflectx
+
+import (
+ "reflect"
+ "strings"
+ "testing"
+)
+
+type mapperString struct {
+ fn func(string) string
+}
+
+func mapperStringMaker(fn interface{}) Func {
+ f := fn.(func(string) string)
+ return &mapperString{fn: f}
+}
+
+func (c *mapperString) Name() string {
+ return "testMapperString"
+}
+
+func (c *mapperString) Type() reflect.Type {
+ return reflect.TypeOf(c.fn)
+}
+
+func (c *mapperString) Call(args []interface{}) []interface{} {
+ out := c.fn(args[0].(string))
+ return []interface{}{out}
+}
+
+func (c *mapperString) Call1x1(v interface{}) interface{} {
+ return c.fn(v.(string))
+}
+
+func TestMakeFunc(t *testing.T) {
+ RegisterFunc(reflect.TypeOf((*func(string) string)(nil)).Elem(),
mapperStringMaker)
+ fn := func(str string) string {
+ return string(str)
+ }
+ madeFn := MakeFunc(fn)
+
+ if got, want := madeFn.Name(), "testMapperString"; got != want {
+ t.Fatalf("MakeFunc(fn).Name()=%v, want %v", got, want)
+ }
+}
+
+func TestCallNoPanic(t *testing.T) {
+ RegisterFunc(reflect.TypeOf((*func(string) string)(nil)).Elem(),
mapperStringMaker)
+ fn := func(str string) string {
+ return string(str)
+ }
+ madeFn := MakeFunc(fn)
+
+ ret, err := CallNoPanic(madeFn, []interface{}{"tester"})
+ if err != nil {
+ t.Fatalf("CallNoPanic(madeFn, [\"tester\"]) errored %v, want
nil", err)
+ }
+ if got, want := ret[0].(string), string("tester"); got != want {
+ t.Fatalf("CallNoPanic(madeFn, [\"tester\"]) got %v, want %v",
got, want)
+ }
+}
+
+func TestCallNoPanic_Panic(t *testing.T) {
+ RegisterFunc(reflect.TypeOf((*func(string) string)(nil)).Elem(),
mapperStringMaker)
+ fn := func(str string) string {
+ if str == "tester" {
+ panic("OH NO!")
+ }
+ return string(str)
+ }
+ madeFn := MakeFunc(fn)
+
+ _, err := CallNoPanic(madeFn, []interface{}{"tester"})
+ if err == nil {
+ t.Fatalf("CallNoPanic(madeFn, [\"tester\"]) didn't error when
it should have")
+ }
+ if !strings.Contains(err.Error(), "OH NO!") {
+ t.Fatalf("CallNoPanic(madeFn, [\"tester\"]) errored %v, should
have contained OH NO!", err)
Review comment:
Same as above, if wrapping an error put it at the end.
##########
File path: sdks/go/pkg/beam/core/util/reflectx/call_test.go
##########
@@ -0,0 +1,125 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package reflectx
+
+import (
+ "reflect"
+ "strings"
+ "testing"
+)
+
+type mapperString struct {
+ fn func(string) string
+}
+
+func mapperStringMaker(fn interface{}) Func {
+ f := fn.(func(string) string)
+ return &mapperString{fn: f}
+}
+
+func (c *mapperString) Name() string {
+ return "testMapperString"
+}
+
+func (c *mapperString) Type() reflect.Type {
+ return reflect.TypeOf(c.fn)
+}
+
+func (c *mapperString) Call(args []interface{}) []interface{} {
+ out := c.fn(args[0].(string))
+ return []interface{}{out}
+}
+
+func (c *mapperString) Call1x1(v interface{}) interface{} {
+ return c.fn(v.(string))
+}
+
+func TestMakeFunc(t *testing.T) {
+ RegisterFunc(reflect.TypeOf((*func(string) string)(nil)).Elem(),
mapperStringMaker)
+ fn := func(str string) string {
+ return string(str)
+ }
+ madeFn := MakeFunc(fn)
+
+ if got, want := madeFn.Name(), "testMapperString"; got != want {
+ t.Fatalf("MakeFunc(fn).Name()=%v, want %v", got, want)
+ }
+}
+
+func TestCallNoPanic(t *testing.T) {
+ RegisterFunc(reflect.TypeOf((*func(string) string)(nil)).Elem(),
mapperStringMaker)
+ fn := func(str string) string {
+ return string(str)
+ }
+ madeFn := MakeFunc(fn)
+
+ ret, err := CallNoPanic(madeFn, []interface{}{"tester"})
+ if err != nil {
+ t.Fatalf("CallNoPanic(madeFn, [\"tester\"]) errored %v, want
nil", err)
Review comment:
You probably remember from the other PR, but put errors at the end of
format strings, after a colon.
I forgot to mention why in the other PR. It's Go convention so that you can
see the source errors in sequence and easily be able to read where one ends and
another begins.
--
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: 738564)
Time Spent: 2h (was: 1h 50m)
> Increase unit testing in the reflectx package
> ---------------------------------------------
>
> Key: BEAM-13904
> URL: https://issues.apache.org/jira/browse/BEAM-13904
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-go
> Reporter: Jack McCluskey
> Assignee: Danny McCormick
> Priority: P2
> Labels: starter
> Time Spent: 2h
> Remaining Estimate: 0h
>
> Increase unit testing coverage in the [reflectx
> package|https://github.com/apache/beam/tree/release-2.36.0/sdks/go/pkg/beam/core/util/reflectx]
> We want code coverage at or above 50%, it is currently at 7.2%.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)