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/05 06:07:53 UTC

[GitHub] [beam] ZhengLin-Li commented on a diff in pull request #24772: [#21391]Increase unit testing coverage in the exec package

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


##########
sdks/go/pkg/beam/core/runtime/exec/translate_test.go:
##########
@@ -318,3 +320,197 @@ func makeWindowMappingFn(w *window.Fn) (*pipepb.FunctionSpec, error) {
 	}
 	return wFn, nil
 }
+
+func TestInputIdToIndex(t *testing.T) {
+	tests := []struct {
+		in   string
+		want int
+	}{
+		{ // does not start with i
+			"90",
+			0,
+		},
+		{ // start with i
+			"i0",
+			0,
+		},
+		{
+			"i1",
+			1,
+		},
+		{
+			"i10",
+			10,
+		},
+	}
+
+	for _, test := range tests {
+		got, err := inputIdToIndex(test.in)
+		if !strings.HasPrefix(test.in, "i") {
+			if err == nil {
+				t.Errorf("Should return err when string does not has a prefix of i, but didn't. inputIdToIndex(%v) = (%v, %v)", test.in, got, err)
+			}
+		} else {
+			if got != test.want {
+				t.Errorf("Can not correctly convert inputId to index. inputIdToIndex(%v) = (%v, %v), want %v", test.in, got, err, test.want)
+			}
+		}
+	}
+}
+
+func TestIndexToInputId(t *testing.T) {
+	tests := []struct {
+		in   int
+		want string
+	}{
+		{
+			1,
+			"i1",
+		},
+		{
+			1000,
+			"i1000",
+		},
+	}
+
+	for _, test := range tests {
+		got := indexToInputId(test.in)
+		if got != test.want {
+			t.Errorf("Can not correctly convert index to inputId. indexToInputId(%v) = (%v), want %v", test.in, got, test.want)
+		}
+	}
+}
+
+func TestUnmarshalPort(t *testing.T) {
+	var port fnpb.RemoteGrpcPort
+
+	tests := []struct {
+		inputData   []byte
+		outputPort  Port
+		outputStr   string
+		outputError error
+	}{
+		{
+			inputData:   []byte{},
+			outputPort:  Port{URL: port.GetApiServiceDescriptor().GetUrl()},
+			outputStr:   fnpb.RemoteGrpcPort{}.CoderId,
+			outputError: nil,
+		},
+	}
+
+	for _, test := range tests {
+		port, str, err := unmarshalPort(test.inputData)
+		if err != nil && test.outputError == nil {
+			t.Errorf("There is an error where should not be. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+		} else if err != nil && err != test.outputError {
+			t.Errorf("There is an error that does not meet expectation. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+		} else if port != test.outputPort {
+			t.Errorf("The output port is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+		} else if str != test.outputStr {
+			t.Errorf("The output string is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+		}
+	}
+}
+
+func TestUnmarshalPlan(t *testing.T) {
+	transform := pipepb.PTransform{
+		Spec: &pipepb.FunctionSpec{
+			Urn: urnDataSource,
+		},
+		Outputs: map[string]string{},
+	}
+	tests := []struct {
+		name        string
+		inputDesc   *fnpb.ProcessBundleDescriptor
+		outputPlan  *Plan
+		outputError error
+	}{
+		{
+			name: "test_no_root_units",
+			inputDesc: &fnpb.ProcessBundleDescriptor{
+				Id:         "",
+				Transforms: map[string]*pipepb.PTransform{},
+			},
+			outputPlan:  nil,
+			outputError: errors.Errorf("no root units"),

Review Comment:
   Should we use `errors.New(message string)` instead of `errors.errorf(format string, args ...any)` when we do not need to formant arguments in the output string?



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