This is an automated email from the ASF dual-hosted git repository.

altay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 28d8115  Avoid depending on context formating in hooks_test
     new 190162d  Merge pull request #8405 from lostluck/fixTest
28d8115 is described below

commit 28d8115464bd0c397899af896e42b6dc9a731f44
Author: Robert Burke <[email protected]>
AuthorDate: Thu Apr 25 23:13:39 2019 +0000

    Avoid depending on context formating in hooks_test
---
 sdks/go/pkg/beam/core/util/hooks/hooks_test.go | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/sdks/go/pkg/beam/core/util/hooks/hooks_test.go 
b/sdks/go/pkg/beam/core/util/hooks/hooks_test.go
index 6c37aec..06b0d9a 100644
--- a/sdks/go/pkg/beam/core/util/hooks/hooks_test.go
+++ b/sdks/go/pkg/beam/core/util/hooks/hooks_test.go
@@ -17,7 +17,6 @@ package hooks
 
 import (
        "context"
-       "fmt"
        "testing"
 
        fnpb "github.com/apache/beam/sdks/go/pkg/beam/model/fnexecution_v1"
@@ -25,13 +24,20 @@ import (
 
 type contextKey string
 
+const (
+       initKey   = contextKey("init_key")
+       reqKey    = contextKey("req_key")
+       initValue = "initValue"
+       reqValue  = "reqValue"
+)
+
 func initializeHooks() {
        activeHooks["test"] = Hook{
                Init: func(ctx context.Context) (context.Context, error) {
-                       return context.WithValue(ctx, contextKey("init_key"), 
"value"), nil
+                       return context.WithValue(ctx, initKey, initValue), nil
                },
                Req: func(ctx context.Context, req *fnpb.InstructionRequest) 
(context.Context, error) {
-                       return context.WithValue(ctx, contextKey("req_key"), 
"value"), nil
+                       return context.WithValue(ctx, reqKey, reqValue), nil
                },
        }
 }
@@ -41,12 +47,12 @@ func TestInitContextPropagation(t *testing.T) {
        ctx := context.Background()
        var err error
 
-       expected := `context.Background.WithValue("init_key", "value")`
+       expected := initValue
        ctx, err = RunInitHooks(ctx)
        if err != nil {
                t.Errorf("got %v error, wanted no error", err)
        }
-       actual := ctx.(fmt.Stringer).String()
+       actual := ctx.Value(initKey)
        if actual != expected {
                t.Errorf("Got %s, wanted %s", actual, expected)
        }
@@ -56,9 +62,9 @@ func TestRequestContextPropagation(t *testing.T) {
        initializeHooks()
        ctx := context.Background()
 
-       expected := `context.Background.WithValue("req_key", "value")`
+       expected := reqValue
        ctx = RunRequestHooks(ctx, nil)
-       actual := ctx.(fmt.Stringer).String()
+       actual := ctx.Value(reqKey)
        if actual != expected {
                t.Errorf("Got %s, wanted %s", actual, expected)
        }

Reply via email to