lostluck commented on code in PR #24811: URL: https://github.com/apache/beam/pull/24811#discussion_r1062711545
########## 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, + }, + } + Review Comment: I don't mind the indirection for a single test structure, but there's no need to put the values in separate variables first. Imagine there were additional test cases, defining everything with str1, bytes3, ahead of time adds no value and hurts readability. ```suggestion test := struct { opt sqlx.Option }{ opt: sqlx.Option{ Urn: "this is a string", Payload: []byte{1, 2, 3, 4}, }, } ``` Similarly below in the other tests. ########## 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) Review Comment: typo, and a bit verbose/repetitive, but still an improvement! Consider the following instead: ```suggestion t.Errorf("options.Add(%v) failed. For the customs field in options, got %v, want %v", test.opt, o.customs, test.opt) ``` This says the same thing, without the redundant information, and fixes the minor grammar nit (bad grammar is English's fault, to be clear). ########## 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: ```suggestion t.Errorf("Dialect(%v) = %v, want not nil", test.dialect, option) ``` ########## 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) Review Comment: When it makes sense, ` = ` can replace `got` in the test log. Even if we already check that the output is nil, it's better to simply pass in the variable instead of replacing it with a generic value (in this case, using `nil`, instead of `option` as an argument to Errorf.) ```suggestion t.Errorf("Input(%v, %v) = %v, want not nil", test.inputName, test.inputIn, option) ``` ########## 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) + } + option(o) + if !reflect.DeepEqual(o.dialect, test.dialect) { + t.Errorf("The function that Input(%v) returned did not work correctly. For the feild dialect in options, got %v, want %v", test.dialect, o.dialect, test.dialect) + } +} + +func TestExpansionAddr(t *testing.T) { + addr1 := "this is a string" + test := struct { + addr string + }{ + addr: addr1, + } + + o := &options{} + option := ExpansionAddr(test.addr) + if option == nil { + t.Errorf("ExpansionAddr(%v) = %v, it returns a nil value, which is not wanted", test.addr, nil) Review Comment: ```suggestion t.Errorf("ExpansionAddr(%v) = %v, want not nil", test.addr, option) ``` ########## 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) Review Comment: Typo on the world field. ```suggestion t.Errorf("The function that Input(%v, %v) returned did not work correctly. For the field inputs in options, got %v, want %v", test.inputName, test.inputIn, o.inputs, test.inputIn) ``` Otherwise, I can't think of a sufficiently better way to express this situation. I'd be inclined to replace "did not work correctly" with "failed", but "The function that Input(%v, %v) returned failed" is awkward in a different way. So I recommend fixing the typo and leaving the rest. ########## 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) + } + option(o) + if !reflect.DeepEqual(o.dialect, test.dialect) { + t.Errorf("The function that Input(%v) returned did not work correctly. For the feild dialect in options, got %v, want %v", test.dialect, o.dialect, test.dialect) + } +} + +func TestExpansionAddr(t *testing.T) { + addr1 := "this is a string" + test := struct { + addr string + }{ + addr: addr1, + } + + o := &options{} + option := ExpansionAddr(test.addr) + if option == nil { + t.Errorf("ExpansionAddr(%v) = %v, it returns a nil value, which is not wanted", test.addr, nil) + } + option(o) + if !reflect.DeepEqual(o.expansionAddr, test.addr) { + t.Errorf("The function that ExpansionAddr(%v) returned did not work correctly. For the feild expansionAddr in options, got %v, want %v", test.addr, o.expansionAddr, test.addr) Review Comment: ```suggestion t.Errorf("The function that ExpansionAddr(%v) returned did not work correctly. For the field expansionAddr in options, got %v, want %v", test.addr, o.expansionAddr, test.addr) ``` ########## 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) + } + option(o) + if !reflect.DeepEqual(o.dialect, test.dialect) { + t.Errorf("The function that Input(%v) returned did not work correctly. For the feild dialect in options, got %v, want %v", test.dialect, o.dialect, test.dialect) Review Comment: ```suggestion t.Errorf("The function that Input(%v) returned did not work correctly. For the field dialect in options, got %v, want %v", test.dialect, o.dialect, test.dialect) ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
