Skip to content

Commit

Permalink
Migrate testing subpackages from interface{} to any (#24570)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmccluskey authored Dec 7, 2022
1 parent 1ba7821 commit da100f9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions sdks/go/pkg/beam/testing/passert/equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdks/go/pkg/beam/testing/passert/floats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions sdks/go/pkg/beam/testing/passert/passert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions sdks/go/pkg/beam/testing/ptest/ptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions sdks/go/pkg/beam/testing/ptest/ptest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions sdks/go/pkg/beam/testing/teststream/teststream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
Expand Down
20 changes: 10 additions & 10 deletions sdks/go/pkg/beam/testing/teststream/teststream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit da100f9

Please sign in to comment.