lostluck commented on a change in pull request #13272:
URL: https://github.com/apache/beam/pull/13272#discussion_r523124215



##########
File path: sdks/go/pkg/beam/core/runtime/metricsx/metricsx_test.go
##########
@@ -0,0 +1,166 @@
+// 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 metricsx
+
+import (
+       "testing"
+       "time"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/metrics"
+       pipepb "github.com/apache/beam/sdks/go/pkg/beam/model/pipeline_v1"
+       "github.com/google/go-cmp/cmp"
+)
+
+func TestFromMonitoringInfos_Counters(t *testing.T) {
+       var value int64 = 15
+       want := metrics.CounterResult{
+               Attempted: 15,
+               Committed: -1,
+               Key: metrics.StepKey{
+                       Step:      "main.customDoFn",
+                       Name:      "customCounter",
+                       Namespace: "customDoFn",
+               }}
+
+       payload, err := Int64Counter(value)
+       if err != nil {
+               t.Fatalf("Failed to encode Int64Counter: %v", err)
+       }
+
+       labels := map[string]string{
+               "PTRANSFORM": "main.customDoFn",
+               "NAMESPACE":  "customDoFn",
+               "NAME":       "customCounter",
+       }
+
+       mInfo := &pipepb.MonitoringInfo{
+               Urn:     UrnToString(UrnUserSumInt64),
+               Type:    UrnToType(UrnUserSumInt64),
+               Labels:  labels,
+               Payload: payload,
+       }
+
+       attempted := []*pipepb.MonitoringInfo{mInfo}
+       committed := []*pipepb.MonitoringInfo{}
+
+       got := FromMonitoringInfos(attempted, committed).AllMetrics().Counters()
+       size := len(got)
+       if size < 1 {
+               t.Fatalf("Invalid array's size: got: %v, want: %v", size, 1)
+       }
+       if d := cmp.Diff(got[0], want); d != "" {

Review comment:
       You'll want to have want before got when using cmp.Diff. Otherwise your 
diff guidance is wrong.
   
   cmp.Diff(want, got[0]) means the diff will be (-want,+got) that is saying 
what is missing from want, and extra in got, which is a useful way to read 
them. cmp.Diff(got[0],want) means the diff will be (+want,-got), which will be 
confusing.
   
   
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to