You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by da...@apache.org on 2022/12/07 15:36:10 UTC

[beam] branch master updated: Migrate testing subpackages from interface{} to any (#24570)

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

damccorm 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 da100f967a6 Migrate testing subpackages from interface{} to any (#24570)
da100f967a6 is described below

commit da100f967a6fbc86a2cc4ae6c9fe69180c70e74f
Author: Jack McCluskey <34...@users.noreply.github.com>
AuthorDate: Wed Dec 7 10:36:03 2022 -0500

    Migrate testing subpackages from interface{} to any (#24570)
---
 sdks/go/pkg/beam/testing/passert/equals.go           |  4 ++--
 sdks/go/pkg/beam/testing/passert/floats.go           |  2 +-
 sdks/go/pkg/beam/testing/passert/passert.go          |  4 ++--
 sdks/go/pkg/beam/testing/ptest/ptest.go              |  8 ++++----
 sdks/go/pkg/beam/testing/ptest/ptest_test.go         |  6 +++---
 sdks/go/pkg/beam/testing/teststream/teststream.go    |  6 +++---
 .../pkg/beam/testing/teststream/teststream_test.go   | 20 ++++++++++----------
 7 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/sdks/go/pkg/beam/testing/passert/equals.go b/sdks/go/pkg/beam/testing/passert/equals.go
index 2311e961e43..36ccf659259 100644
--- a/sdks/go/pkg/beam/testing/passert/equals.go
+++ b/sdks/go/pkg/beam/testing/passert/equals.go
@@ -27,7 +27,7 @@ import (
 // Equals verifies the given collection has the same values as the given
 // values, under coder equality. The values can be provided as single
 // PCollection.
-func Equals(s beam.Scope, col beam.PCollection, values ...interface{}) beam.PCollection {
+func Equals(s beam.Scope, col beam.PCollection, values ...any) beam.PCollection {
 	subScope := s.Scope("passert.Equals")
 	if len(values) == 0 {
 		return Empty(subScope, col)
@@ -44,7 +44,7 @@ func Equals(s beam.Scope, col beam.PCollection, values ...interface{}) beam.PCol
 // given list, under coder equality. The values must be provided as an
 // array or slice. This is equivalent to passing a beam.CreateList PCollection
 // to Equals.
-func EqualsList(s beam.Scope, col beam.PCollection, list interface{}) beam.PCollection {
+func EqualsList(s beam.Scope, col beam.PCollection, list any) beam.PCollection {
 	subScope := s.Scope("passert.EqualsList")
 	if list == nil {
 		return Empty(subScope, col)
diff --git a/sdks/go/pkg/beam/testing/passert/floats.go b/sdks/go/pkg/beam/testing/passert/floats.go
index 8bccd698995..727c313820b 100644
--- a/sdks/go/pkg/beam/testing/passert/floats.go
+++ b/sdks/go/pkg/beam/testing/passert/floats.go
@@ -144,7 +144,7 @@ func (f *boundsFn) ProcessElement(_ []byte, col func(*beam.T) bool) error {
 }
 
 func toFloat(input beam.T) float64 {
-	return reflect.ValueOf(input.(interface{})).Convert(reflectx.Float64).Interface().(float64)
+	return reflect.ValueOf(input.(any)).Convert(reflectx.Float64).Interface().(float64)
 }
 
 func validateNonComplexNumber(t reflect.Type) error {
diff --git a/sdks/go/pkg/beam/testing/passert/passert.go b/sdks/go/pkg/beam/testing/passert/passert.go
index c3dceaadb76..990d3c8c4d4 100644
--- a/sdks/go/pkg/beam/testing/passert/passert.go
+++ b/sdks/go/pkg/beam/testing/passert/passert.go
@@ -124,13 +124,13 @@ func index(enc beam.ElementEncoder, iter func(*beam.T) bool) (map[string]indexEn
 }
 
 // True asserts that all elements satisfy the given predicate.
-func True(s beam.Scope, col beam.PCollection, fn interface{}) beam.PCollection {
+func True(s beam.Scope, col beam.PCollection, fn any) beam.PCollection {
 	fail(s, filter.Exclude(s, col, fn), "predicate(%v) = false, want true")
 	return col
 }
 
 // False asserts that the given predicate does not satisfy any element in the condition.
-func False(s beam.Scope, col beam.PCollection, fn interface{}) beam.PCollection {
+func False(s beam.Scope, col beam.PCollection, fn any) beam.PCollection {
 	fail(s, filter.Include(s, col, fn), "predicate(%v) = true, want false")
 	return col
 }
diff --git a/sdks/go/pkg/beam/testing/ptest/ptest.go b/sdks/go/pkg/beam/testing/ptest/ptest.go
index b606b7ebf66..5f76e618adf 100644
--- a/sdks/go/pkg/beam/testing/ptest/ptest.go
+++ b/sdks/go/pkg/beam/testing/ptest/ptest.go
@@ -32,28 +32,28 @@ import (
 // TODO(herohde) 7/10/2017: add hooks to verify counters, logs, etc.
 
 // Create creates a pipeline and a PCollection with the given values.
-func Create(values []interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection) {
+func Create(values []any) (*beam.Pipeline, beam.Scope, beam.PCollection) {
 	p := beam.NewPipeline()
 	s := p.Root()
 	return p, s, beam.Create(s, values...)
 }
 
 // CreateList creates a pipeline and a PCollection with the given values.
-func CreateList(values interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection) {
+func CreateList(values any) (*beam.Pipeline, beam.Scope, beam.PCollection) {
 	p := beam.NewPipeline()
 	s := p.Root()
 	return p, s, beam.CreateList(s, values)
 }
 
 // Create2 creates a pipeline and 2 PCollections with the given values.
-func Create2(a, b []interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
+func Create2(a, b []any) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
 	p := beam.NewPipeline()
 	s := p.Root()
 	return p, s, beam.Create(s, a...), beam.Create(s, b...)
 }
 
 // CreateList2 creates a pipeline and 2 PCollections with the given values.
-func CreateList2(a, b interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
+func CreateList2(a, b any) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
 	p := beam.NewPipeline()
 	s := p.Root()
 	return p, s, beam.CreateList(s, a), beam.CreateList(s, b)
diff --git a/sdks/go/pkg/beam/testing/ptest/ptest_test.go b/sdks/go/pkg/beam/testing/ptest/ptest_test.go
index 8b07fa90a37..cbedd6b406f 100644
--- a/sdks/go/pkg/beam/testing/ptest/ptest_test.go
+++ b/sdks/go/pkg/beam/testing/ptest/ptest_test.go
@@ -22,7 +22,7 @@ import (
 )
 
 func TestCreate(t *testing.T) {
-	inputs := []interface{}{"a", "b", "c"}
+	inputs := []any{"a", "b", "c"}
 	p, s, col := Create(inputs)
 	passert.EqualsList(s, col, inputs)
 	if err := Run(p); err != nil {
@@ -40,8 +40,8 @@ func TestCreateList(t *testing.T) {
 }
 
 func TestCreate2(t *testing.T) {
-	inputOne := []interface{}{"a", "b", "c"}
-	inputTwo := []interface{}{"d", "e", "f", "g"}
+	inputOne := []any{"a", "b", "c"}
+	inputTwo := []any{"d", "e", "f", "g"}
 	p, s, colOne, colTwo := Create2(inputOne, inputTwo)
 	passert.EqualsList(s, colOne, inputOne)
 	passert.EqualsList(s, colTwo, inputTwo)
diff --git a/sdks/go/pkg/beam/testing/teststream/teststream.go b/sdks/go/pkg/beam/testing/teststream/teststream.go
index 11f2e1cea5f..050e57bf04c 100644
--- a/sdks/go/pkg/beam/testing/teststream/teststream.go
+++ b/sdks/go/pkg/beam/testing/teststream/teststream.go
@@ -111,7 +111,7 @@ func (c *Config) AdvanceProcessingTimeToInfinity() {
 // Type mismatches on this or subsequent calls will cause AddElements to return an error.
 //
 // Element types must have built-in coders in Beam.
-func (c *Config) AddElements(timestamp int64, elements ...interface{}) error {
+func (c *Config) AddElements(timestamp int64, elements ...any) error {
 	t := reflect.TypeOf(elements[0])
 	if c.elmType == nil {
 		c.elmType = typex.New(t)
@@ -144,13 +144,13 @@ func (c *Config) AddElements(timestamp int64, elements ...interface{}) error {
 // Calls into AddElements, which panics if an inserted type does not match a previously inserted element type.
 //
 // Element types must have built-in coders in Beam.
-func (c *Config) AddElementList(timestamp int64, elements interface{}) error {
+func (c *Config) AddElementList(timestamp int64, elements any) error {
 	val := reflect.ValueOf(elements)
 	if val.Kind() != reflect.Slice && val.Kind() != reflect.Array {
 		return fmt.Errorf("input %v must be a slice or array", elements)
 	}
 
-	var inputs []interface{}
+	var inputs []any
 	for i := 0; i < val.Len(); i++ {
 		inputs = append(inputs, val.Index(i).Interface())
 	}
diff --git a/sdks/go/pkg/beam/testing/teststream/teststream_test.go b/sdks/go/pkg/beam/testing/teststream/teststream_test.go
index 7b4a0c25637..22c38b03c6e 100644
--- a/sdks/go/pkg/beam/testing/teststream/teststream_test.go
+++ b/sdks/go/pkg/beam/testing/teststream/teststream_test.go
@@ -76,23 +76,23 @@ func TestAdvanceProcessingTime(t *testing.T) {
 func TestAddElements(t *testing.T) {
 	tests := []struct {
 		name          string
-		elementGroups [][]interface{}
+		elementGroups [][]any
 	}{
 		{
 			"bools",
-			[][]interface{}{{true, false}},
+			[][]any{{true, false}},
 		},
 		{
 			"multiple bools",
-			[][]interface{}{{true, false}, {true, false}},
+			[][]any{{true, false}, {true, false}},
 		},
 		{
 			"strings",
-			[][]interface{}{{"test", "other test"}},
+			[][]any{{"test", "other test"}},
 		},
 		{
 			"floats",
-			[][]interface{}{{1.1, 2.2, 3.3}},
+			[][]any{{1.1, 2.2, 3.3}},
 		},
 	}
 	for _, tc := range tests {
@@ -119,23 +119,23 @@ func TestAddElements(t *testing.T) {
 func TestAddElementList(t *testing.T) {
 	tests := []struct {
 		name          string
-		elementGroups [][]interface{}
+		elementGroups [][]any
 	}{
 		{
 			"bools",
-			[][]interface{}{{true, false}},
+			[][]any{{true, false}},
 		},
 		{
 			"multiple bools",
-			[][]interface{}{{true, false}, {true, false}},
+			[][]any{{true, false}, {true, false}},
 		},
 		{
 			"strings",
-			[][]interface{}{{"test", "other test"}},
+			[][]any{{"test", "other test"}},
 		},
 		{
 			"floats",
-			[][]interface{}{{1.1, 2.2, 3.3}},
+			[][]any{{1.1, 2.2, 3.3}},
 		},
 	}
 	for _, tc := range tests {