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

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

                Author: ASF GitHub Bot
            Created on: 07/Jul/21 17:06
            Start Date: 07/Jul/21 17:06
    Worklog Time Spent: 10m 
      Work Description: lostluck commented on a change in pull request #15131:
URL: https://github.com/apache/beam/pull/15131#discussion_r665538667



##########
File path: sdks/go/pkg/beam/testing/passert/sum_test.go
##########
@@ -0,0 +1,111 @@
+// 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 passert
+
+import (
+        "strings"
+       "testing"

Review comment:
       You'll want to add "go fmt" to your save hooks. Go is big on automatic 
formatting of the code, and changing things to tabs rather than spaces.

##########
File path: sdks/go/pkg/beam/testing/passert/sum_test.go
##########
@@ -0,0 +1,111 @@
+// 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 passert
+
+import (
+        "strings"
+       "testing"
+
+        "github.com/apache/beam/sdks/go/pkg/beam"
+        "github.com/apache/beam/sdks/go/pkg/beam/testing/ptest"
+)
+
+func TestSum_good(t *testing.T) {
+       tests := []struct {
+               name   string
+               values []int
+               size   int
+               total  int
+       }{
+               {
+                       "all positive",
+                       []int{1, 2, 3, 4, 5},
+                       5,
+                       15,
+               },
+               {
+                       "all negative",
+                       []int{-1, -2, -3, -4, -5},
+                       5,
+                       -15,
+               },
+               {
+                       "mixed",
+                       []int{1, -2, 3, -4, 5},
+                       5,
+                       3,
+               },
+               {
+                       "empty",
+                       []int{},
+                       0,
+                       0,
+               },
+       }
+       for _, tc := range tests {
+               p, s := beam.NewPipelineWithRoot()
+               col := beam.CreateList(s, tc.values)
+               Sum(s, col, tc.name, tc.size, tc.total)
+               if err := ptest.Run(p); err != nil {
+                       t.Errorf("Pipeline failed: %v", err)
+               }
+       }
+}
+
+func TestSum_bad(t *testing.T) {
+       tests := []struct {
+               name       string
+               col        []int
+               size       int
+               total      int
+               errorParts []string
+       }{
+               {
+                       "bad size",
+                       []int{1, 2, 3, 4, 5},
+                       4,
+                       15,
+                       []string{"{15, size: 5}", "want {15, size:4}"},
+               },
+               {
+                       "bad total",
+                       []int{1, 2, 3, 4, 5},
+                       5,
+                       16,
+                       []string{"{15, size: 5}", "want {16, size:5}"},
+               },
+       }
+       for _, tc := range tests {
+               p, s := beam.NewPipelineWithRoot()
+               col := beam.CreateList(s, tc.col)
+               Sum(s, col, tc.name, tc.size, tc.total)
+               if err := ptest.Run(p); err == nil {
+                       t.Errorf("Pipeline succeeded but should have failed: 
%v", tc.name)

Review comment:
       Go Style wise, the idiomatic way of writing this is to use a t.Fatalf 
instead of an t.Errorf, and avoid the indentation that an else block ads. 
t.Fatalf aborts the test, so there's no need to put things into an else block.
   
   Note that this will abort any subsequent test cases, since the body of the 
test is not using a sub test, using t.Run. See https://blog.golang.org/subtests 
for more details.




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

> [Go SDK] PAssert improvements
> -----------------------------
>
>                 Key: BEAM-12548
>                 URL: https://issues.apache.org/jira/browse/BEAM-12548
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-go
>            Reporter: Robert Burke
>            Assignee: Jack McCluskey
>            Priority: P2
>          Time Spent: 3h 10m
>  Remaining Estimate: 0h
>
> The Go SDK Passert package could be more helpful.
> It could haveĀ  GoDoc examples for correct and less clear use of each of the 
> functions (like both the variadic and PCollection approaches forĀ  
> passert.Equals).
> There could be better/more sophisticated handling for floating point values, 
> eg with thresholds.
> There could be special/magic handling for synthetic KV types that could then 
> be used for handling Equals against KV PCollections.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to