[ 
https://issues.apache.org/jira/browse/BEAM-13904?focusedWorklogId=738719&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-738719
 ]

ASF GitHub Bot logged work on BEAM-13904:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Mar/22 12:53
            Start Date: 09/Mar/22 12:53
    Worklog Time Spent: 10m 
      Work Description: damccorm commented on a change in pull request #17024:
URL: https://github.com/apache/beam/pull/17024#discussion_r822617244



##########
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:
       Yeah that makes sense, good call - updated!




-- 
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: 738719)
    Time Spent: 2h 10m  (was: 2h)

> 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 10m
>  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)

Reply via email to