You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2023/01/06 01:33:39 UTC

[GitHub] [beam] ZhengLin-Li commented on a diff in pull request #24811: [#21384] Add unit tests to the sql package

ZhengLin-Li commented on code in PR #24811:
URL: https://github.com/apache/beam/pull/24811#discussion_r1063027057


##########
sdks/go/pkg/beam/transforms/sql/sql_test.go:
##########
@@ -0,0 +1,103 @@
+// 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 sql
+
+import (
+	"github.com/apache/beam/sdks/v2/go/pkg/beam"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/sql/sqlx"
+	"reflect"
+	"testing"
+)
+
+func TestOptions_Add(t *testing.T) {
+	str := "this is a string"
+	bytes := []byte{1, 2, 3, 4}
+	test := struct {
+		opt sqlx.Option
+	}{
+
+		opt: sqlx.Option{
+			Urn:     str,
+			Payload: bytes,
+		},
+	}
+
+	o := options{}
+	o.Add(test.opt)
+	if o.customs == nil || !reflect.DeepEqual(o.customs[len(o.customs)-1], test.opt) {
+		t.Errorf("The method options.Add(%v) did not successfully perform the add operation. For the feild customs in options, got %v, want %v", test.opt, o.customs, test.opt)
+	}
+}
+
+func TestInput(t *testing.T) {
+	name1 := "this is a string"
+	collection1 := beam.PCollection{}
+	test := struct {
+		inputName string
+		inputIn   beam.PCollection
+	}{
+		inputName: name1,
+		inputIn:   collection1,
+	}
+
+	o := &options{inputs: make(map[string]beam.PCollection)}
+	option := Input(test.inputName, test.inputIn)
+	if option == nil {
+		t.Errorf("Input(%v, %v) = %v, it returns a nil value, which is not wanted", test.inputName, test.inputIn, nil)
+	}
+	option(o)
+	if o.inputs == nil || !reflect.DeepEqual(o.inputs[test.inputName], test.inputIn) {
+		t.Errorf("The function that Input(%v, %v) returned did not work correctly. For the feild inputs in options, got %v, want %v", test.inputName, test.inputIn, o.inputs, test.inputIn)
+	}
+}
+
+func TestDialect(t *testing.T) {
+	dialect1 := "this is a string"
+	test := struct {
+		dialect string
+	}{
+		dialect: dialect1,
+	}
+
+	o := &options{}
+	option := Dialect(test.dialect)
+	if option == nil {
+		t.Errorf("Dialect(%v) = %v, it returns a nil value, which is not wanted", test.dialect, nil)

Review Comment:
   If I change `nil` to `option`, my IDE suggests that `Placeholder argument is not a function call (%v) `. Now that we have checked `option == nil`, I am wondering if maybe we could use `nil` instead of `option`?



-- 
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: github-unsubscribe@beam.apache.org

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