[
https://issues.apache.org/jira/browse/BEAM-13889?focusedWorklogId=745249&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-745249
]
ASF GitHub Bot logged work on BEAM-13889:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 21/Mar/22 16:56
Start Date: 21/Mar/22 16:56
Worklog Time Spent: 10m
Work Description: lostluck commented on a change in pull request #17124:
URL: https://github.com/apache/beam/pull/17124#discussion_r831332840
##########
File path: sdks/go/pkg/beam/core/util/jsonx/jsonx_test.go
##########
@@ -0,0 +1,82 @@
+// 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 jsonx
+
+import (
+ "math"
+ "testing"
+)
+
+type someStruct struct {
+ SomeNumber int64
+ SomeString string
+ SomeBoolean bool
+}
+
+func (s *someStruct) equals(other *someStruct) bool {
+ return (s.SomeNumber == other.SomeNumber) && (s.SomeString ==
other.SomeString) && (s.SomeBoolean == other.SomeBoolean)
+}
+
+func TestEncodeDecode(t *testing.T) {
+ var tests = []struct {
+ name string
+ inputNum int64
+ inputString string
+ inputBool bool
+ }{
+ {
+ "simple inputs",
+ 10,
+ "information",
+ true,
+ },
+ {
+ "default inputs",
+ 0,
+ "",
+ false,
+ },
+ {
+ "maximum int",
+ math.MaxInt64,
+ "big int",
+ true,
+ },
+ {
+ "minimum int",
+ math.MinInt64,
+ "little int",
+ false,
+ },
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ inputStruct := &someStruct{SomeNumber: test.inputNum,
SomeString: test.inputString, SomeBoolean: test.inputBool}
+ enc, err := Marshal(inputStruct)
+ if err != nil {
+ t.Fatalf("Marshal(%v) failed, got %v",
inputStruct, err)
+ }
Review comment:
This package existed because internally to Google, we needed to migrate
to the Go 1.16+ version of the JSON package prior to it becoming available, and
abstracting it to a single package allowed all common uses to migrate in one
place, rather than in the few places. It also allowed registering of the
protojson package with the standard JSON encoder, so that protocol buffers
actually get JSON encoded.
There's one place we do need to migrate to schemas before we get rid of the
package though and that is DoFn serialization. It was never a quick enough
change that I could prioritize it.
--
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: 745249)
Time Spent: 1h 50m (was: 1h 40m)
> Add unit testing to the jsonx package
> -------------------------------------
>
> Key: BEAM-13889
> URL: https://issues.apache.org/jira/browse/BEAM-13889
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-go
> Reporter: Jack McCluskey
> Assignee: Jack McCluskey
> Priority: P2
> Labels: starter
> Time Spent: 1h 50m
> Remaining Estimate: 0h
>
> Add basic unit testing to the [jsonx
> package|https://github.com/apache/beam/tree/release-2.36.0/sdks/go/pkg/beam/core/util/jsonx]
> We want code coverage at or above 50%, it is currently at 0%.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)