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

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

                Author: ASF GitHub Bot
            Created on: 05/Jun/20 17:58
            Start Date: 05/Jun/20 17:58
    Worklog Time Spent: 10m 
      Work Description: lostluck commented on a change in pull request #11925:
URL: https://github.com/apache/beam/pull/11925#discussion_r436077202



##########
File path: sdks/go/pkg/beam/core/graph/coder/stringutf8_test.go
##########
@@ -0,0 +1,122 @@
+// 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 coder
+
+import (
+       "bytes"
+       "encoding/base64"
+       "io"
+       "strings"
+       "testing"
+       "unicode/utf8"
+)
+
+var testValues = []string{
+       "",
+       "a",
+       "13",
+       "hello",
+       "a longer string with spaces and all that",
+       "a string with a \n newline",
+       "スタリング",
+       "I am the very model of a modern major general.\nI've information 
animal, vegetable, and mineral",
+}
+
+// Base64 encoded versions of the above strings, without the length prefix.
+var testEncodings = []string{
+       "",
+       "YQ",
+       "MTM",
+       "aGVsbG8",
+       "YSBsb25nZXIgc3RyaW5nIHdpdGggc3BhY2VzIGFuZCBhbGwgdGhhdA",
+       "YSBzdHJpbmcgd2l0aCBhIAogbmV3bGluZQ",
+       "44K544K_44Oq44Oz44Kw",
+       
"SSBhbSB0aGUgdmVyeSBtb2RlbCBvZiBhIG1vZGVybiBtYWpvciBnZW5lcmFsLgpJJ3ZlIGluZm9ybWF0aW9uIGFuaW1hbCwgdmVnZXRhYmxlLCBhbmQgbWluZXJhbA",
+}
+
+// TestLen serves as a verification that string lengths
+// match their equivalent byte lengths, and not their rune
+// representation.
+func TestLen(t *testing.T) {
+       runeCount := []int{0, 1, 2, 5, 40, 25, 5, 94}
+       for i, s := range testValues {
+               if got, want := len(s), len([]byte(s)); got != want {
+                       t.Errorf("string and []byte len do not match. got %v, 
want %v", got, want)
+               }
+               if got, want := utf8.RuneCountInString(s), runeCount[i]; got != 
want {
+                       t.Errorf("Rune count of %q change len do not match. got 
%v, want %v", s, got, want)
+               }
+       }
+}
+
+func TestEncodeStringUTF8(t *testing.T) {
+       for i, s := range testValues {
+               s := s
+               want := testEncodings[i]
+               t.Run(s, func(t *testing.T) {
+                       var b strings.Builder
+                       base64enc := base64.NewEncoder(base64.RawURLEncoding, 
&b)
+
+                       if err := encodeStringUTF8(s, base64enc); err != nil {
+                               t.Fatal(err)
+                       }
+                       base64enc.Close()
+                       got := b.String()
+                       if got != want {
+                               t.Errorf("encodeStringUTF8(%q) = %q, want %q", 
s, got, want)
+                       }
+               })
+       }
+}
+
+func TestDecodeStringUTF8(t *testing.T) {
+       for i, s := range testEncodings {
+               s := s
+               want := testValues[i]
+               t.Run(want, func(t *testing.T) {
+                       b := bytes.NewBufferString(s)
+                       base64dec := base64.NewDecoder(base64.RawURLEncoding, b)
+
+                       got, err := decodeStringUTF8(int64(len(want)), 
base64dec)
+                       if err != nil && err != io.EOF {
+                               t.Fatal(err)
+                       }
+                       if got != want {
+                               t.Errorf("decodeStringUTF8(%q) = %q, want %q", 
s, got, want)
+                       }
+               })
+       }
+}
+
+func TestEncodeDecodeStringUTF8LP(t *testing.T) {
+       for _, s := range testValues {
+               want := s
+               t.Run(want, func(t *testing.T) {
+                       var build strings.Builder
+                       if err := EncodeStringUTF8LP(want, &build); err != nil {

Review comment:
       Technically, this test has the LP verification. If the LP weren't 
present, it wouldn't be possible to get the result back again on decode since 
the decoder won't know how much data to read.




----------------------------------------------------------------
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 441951)
    Time Spent: 2h 50m  (was: 2h 40m)

> [Go SDK] Beam Schemas
> ---------------------
>
>                 Key: BEAM-9615
>                 URL: https://issues.apache.org/jira/browse/BEAM-9615
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-go
>            Reporter: Robert Burke
>            Assignee: Robert Burke
>            Priority: P2
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> Schema support is required for advanced cross language features in Beam, and 
> has the opportunity to replace the current default JSON encoding of elements.
> Some quick notes, though a better fleshed out doc with details will be 
> forthcoming:
>  * All base coders should be implemented, and listed as coder capabilities. I 
> think only stringutf8 is missing presently.
>  * Should support fairly arbitrary user types, seamlessly. That is, users 
> should be able to rely on it "just working" if their type is compatible.
>  * Should support schema metadata tagging.
> In particular, one breaking shift in the default will be to explicitly fail 
> pipelines if elements have unexported fields, when no other custom coder has 
> been added. This has been a source of errors/dropped data/keys and a simply 
> warning at construction time won't cut it. However, we could provide a manual 
> "use beam schemas, but ignore unexported fields" registration as a work 
> around.
> Edit: Doc is now at https://s.apache.org/beam-go-schemas



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

Reply via email to