Skip to content

Commit da100f9

Browse files
authored
Migrate testing subpackages from interface{} to any (#24570)
1 parent 1ba7821 commit da100f9

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

sdks/go/pkg/beam/testing/passert/equals.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// Equals verifies the given collection has the same values as the given
2828
// values, under coder equality. The values can be provided as single
2929
// PCollection.
30-
func Equals(s beam.Scope, col beam.PCollection, values ...interface{}) beam.PCollection {
30+
func Equals(s beam.Scope, col beam.PCollection, values ...any) beam.PCollection {
3131
subScope := s.Scope("passert.Equals")
3232
if len(values) == 0 {
3333
return Empty(subScope, col)
@@ -44,7 +44,7 @@ func Equals(s beam.Scope, col beam.PCollection, values ...interface{}) beam.PCol
4444
// given list, under coder equality. The values must be provided as an
4545
// array or slice. This is equivalent to passing a beam.CreateList PCollection
4646
// to Equals.
47-
func EqualsList(s beam.Scope, col beam.PCollection, list interface{}) beam.PCollection {
47+
func EqualsList(s beam.Scope, col beam.PCollection, list any) beam.PCollection {
4848
subScope := s.Scope("passert.EqualsList")
4949
if list == nil {
5050
return Empty(subScope, col)

sdks/go/pkg/beam/testing/passert/floats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (f *boundsFn) ProcessElement(_ []byte, col func(*beam.T) bool) error {
144144
}
145145

146146
func toFloat(input beam.T) float64 {
147-
return reflect.ValueOf(input.(interface{})).Convert(reflectx.Float64).Interface().(float64)
147+
return reflect.ValueOf(input.(any)).Convert(reflectx.Float64).Interface().(float64)
148148
}
149149

150150
func validateNonComplexNumber(t reflect.Type) error {

sdks/go/pkg/beam/testing/passert/passert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ func index(enc beam.ElementEncoder, iter func(*beam.T) bool) (map[string]indexEn
124124
}
125125

126126
// True asserts that all elements satisfy the given predicate.
127-
func True(s beam.Scope, col beam.PCollection, fn interface{}) beam.PCollection {
127+
func True(s beam.Scope, col beam.PCollection, fn any) beam.PCollection {
128128
fail(s, filter.Exclude(s, col, fn), "predicate(%v) = false, want true")
129129
return col
130130
}
131131

132132
// False asserts that the given predicate does not satisfy any element in the condition.
133-
func False(s beam.Scope, col beam.PCollection, fn interface{}) beam.PCollection {
133+
func False(s beam.Scope, col beam.PCollection, fn any) beam.PCollection {
134134
fail(s, filter.Include(s, col, fn), "predicate(%v) = true, want false")
135135
return col
136136
}

sdks/go/pkg/beam/testing/ptest/ptest.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ import (
3232
// TODO(herohde) 7/10/2017: add hooks to verify counters, logs, etc.
3333

3434
// Create creates a pipeline and a PCollection with the given values.
35-
func Create(values []interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection) {
35+
func Create(values []any) (*beam.Pipeline, beam.Scope, beam.PCollection) {
3636
p := beam.NewPipeline()
3737
s := p.Root()
3838
return p, s, beam.Create(s, values...)
3939
}
4040

4141
// CreateList creates a pipeline and a PCollection with the given values.
42-
func CreateList(values interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection) {
42+
func CreateList(values any) (*beam.Pipeline, beam.Scope, beam.PCollection) {
4343
p := beam.NewPipeline()
4444
s := p.Root()
4545
return p, s, beam.CreateList(s, values)
4646
}
4747

4848
// Create2 creates a pipeline and 2 PCollections with the given values.
49-
func Create2(a, b []interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
49+
func Create2(a, b []any) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
5050
p := beam.NewPipeline()
5151
s := p.Root()
5252
return p, s, beam.Create(s, a...), beam.Create(s, b...)
5353
}
5454

5555
// CreateList2 creates a pipeline and 2 PCollections with the given values.
56-
func CreateList2(a, b interface{}) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
56+
func CreateList2(a, b any) (*beam.Pipeline, beam.Scope, beam.PCollection, beam.PCollection) {
5757
p := beam.NewPipeline()
5858
s := p.Root()
5959
return p, s, beam.CreateList(s, a), beam.CreateList(s, b)

sdks/go/pkg/beam/testing/ptest/ptest_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func TestCreate(t *testing.T) {
25-
inputs := []interface{}{"a", "b", "c"}
25+
inputs := []any{"a", "b", "c"}
2626
p, s, col := Create(inputs)
2727
passert.EqualsList(s, col, inputs)
2828
if err := Run(p); err != nil {
@@ -40,8 +40,8 @@ func TestCreateList(t *testing.T) {
4040
}
4141

4242
func TestCreate2(t *testing.T) {
43-
inputOne := []interface{}{"a", "b", "c"}
44-
inputTwo := []interface{}{"d", "e", "f", "g"}
43+
inputOne := []any{"a", "b", "c"}
44+
inputTwo := []any{"d", "e", "f", "g"}
4545
p, s, colOne, colTwo := Create2(inputOne, inputTwo)
4646
passert.EqualsList(s, colOne, inputOne)
4747
passert.EqualsList(s, colTwo, inputTwo)

sdks/go/pkg/beam/testing/teststream/teststream.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (c *Config) AdvanceProcessingTimeToInfinity() {
111111
// Type mismatches on this or subsequent calls will cause AddElements to return an error.
112112
//
113113
// Element types must have built-in coders in Beam.
114-
func (c *Config) AddElements(timestamp int64, elements ...interface{}) error {
114+
func (c *Config) AddElements(timestamp int64, elements ...any) error {
115115
t := reflect.TypeOf(elements[0])
116116
if c.elmType == nil {
117117
c.elmType = typex.New(t)
@@ -144,13 +144,13 @@ func (c *Config) AddElements(timestamp int64, elements ...interface{}) error {
144144
// Calls into AddElements, which panics if an inserted type does not match a previously inserted element type.
145145
//
146146
// Element types must have built-in coders in Beam.
147-
func (c *Config) AddElementList(timestamp int64, elements interface{}) error {
147+
func (c *Config) AddElementList(timestamp int64, elements any) error {
148148
val := reflect.ValueOf(elements)
149149
if val.Kind() != reflect.Slice && val.Kind() != reflect.Array {
150150
return fmt.Errorf("input %v must be a slice or array", elements)
151151
}
152152

153-
var inputs []interface{}
153+
var inputs []any
154154
for i := 0; i < val.Len(); i++ {
155155
inputs = append(inputs, val.Index(i).Interface())
156156
}

sdks/go/pkg/beam/testing/teststream/teststream_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,23 @@ func TestAdvanceProcessingTime(t *testing.T) {
7676
func TestAddElements(t *testing.T) {
7777
tests := []struct {
7878
name string
79-
elementGroups [][]interface{}
79+
elementGroups [][]any
8080
}{
8181
{
8282
"bools",
83-
[][]interface{}{{true, false}},
83+
[][]any{{true, false}},
8484
},
8585
{
8686
"multiple bools",
87-
[][]interface{}{{true, false}, {true, false}},
87+
[][]any{{true, false}, {true, false}},
8888
},
8989
{
9090
"strings",
91-
[][]interface{}{{"test", "other test"}},
91+
[][]any{{"test", "other test"}},
9292
},
9393
{
9494
"floats",
95-
[][]interface{}{{1.1, 2.2, 3.3}},
95+
[][]any{{1.1, 2.2, 3.3}},
9696
},
9797
}
9898
for _, tc := range tests {
@@ -119,23 +119,23 @@ func TestAddElements(t *testing.T) {
119119
func TestAddElementList(t *testing.T) {
120120
tests := []struct {
121121
name string
122-
elementGroups [][]interface{}
122+
elementGroups [][]any
123123
}{
124124
{
125125
"bools",
126-
[][]interface{}{{true, false}},
126+
[][]any{{true, false}},
127127
},
128128
{
129129
"multiple bools",
130-
[][]interface{}{{true, false}, {true, false}},
130+
[][]any{{true, false}, {true, false}},
131131
},
132132
{
133133
"strings",
134-
[][]interface{}{{"test", "other test"}},
134+
[][]any{{"test", "other test"}},
135135
},
136136
{
137137
"floats",
138-
[][]interface{}{{1.1, 2.2, 3.3}},
138+
[][]any{{1.1, 2.2, 3.3}},
139139
},
140140
}
141141
for _, tc := range tests {

0 commit comments

Comments
 (0)