This is an automated email from the ASF dual-hosted git repository.
pabloem 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 64e40d2c018 [Playground] Fix Test_getRunOrTestCmd on Go 1.20 (#25379)
64e40d2c018 is described below
commit 64e40d2c018f8e906f4bec32ef67f02734a95721
Author: Timur Sultanov <[email protected]>
AuthorDate: Thu Feb 9 22:38:08 2023 +0400
[Playground] Fix Test_getRunOrTestCmd on Go 1.20 (#25379)
* Fix Test_getRunOrTestCmd on Go 1.20
* Use go_cmp to compare test result with expected value
---
playground/backend/go.mod | 2 +-
.../internal/code_processing/code_processing_test.go | 13 +++++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/playground/backend/go.mod b/playground/backend/go.mod
index 0601cf51427..a2580231ff1 100644
--- a/playground/backend/go.mod
+++ b/playground/backend/go.mod
@@ -30,6 +30,7 @@ require (
github.com/rs/cors v1.8.2
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
+ github.com/google/go-cmp v0.5.9
go.uber.org/goleak v1.2.0
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
@@ -49,7 +50,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da //
indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
- github.com/google/go-cmp v0.5.9 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
diff --git
a/playground/backend/internal/code_processing/code_processing_test.go
b/playground/backend/internal/code_processing/code_processing_test.go
index fb3a2a1313e..f6c7fb19425 100644
--- a/playground/backend/internal/code_processing/code_processing_test.go
+++ b/playground/backend/internal/code_processing/code_processing_test.go
@@ -19,6 +19,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "github.com/google/go-cmp/cmp"
"io/fs"
"os"
"os/exec"
@@ -626,10 +627,18 @@ func Test_getRunOrTestCmd(t *testing.T) {
want: wantTestExec,
},
}
+
+ execComparer := cmp.Comparer(func(a exec.Cmd, b exec.Cmd) bool {
+ return a.Path == b.Path &&
+ cmp.Equal(a.Args, b.Args) &&
+ cmp.Equal(a.Env, b.Env) &&
+ a.Dir == b.Dir
+ })
+
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- if got := getExecuteCmd(tt.args.isUnitTest,
tt.args.executor, tt.args.ctxWithTimeout); !reflect.DeepEqual(got, tt.want) {
- t.Errorf("getExecuteCmd() = %v, want %v", got,
tt.want)
+ if got := getExecuteCmd(tt.args.isUnitTest,
tt.args.executor, tt.args.ctxWithTimeout); !cmp.Equal(got, tt.want,
execComparer) {
+ t.Errorf("getExecuteCmd() = '%v', want '%v',
diff = %v", got, tt.want, cmp.Diff(got, tt.want, execComparer))
}
})
}