From c567e6b55480b0e16e6d447d192ee5d2d7bade3a Mon Sep 17 00:00:00 2001 From: Raphael Simon Date: Tue, 25 Jun 2024 12:59:21 -0700 Subject: [PATCH] Handle Windows --- codegen/example/example_server_test.go | 13 +++---------- grpc/codegen/example_server_test.go | 4 ++-- grpc/codegen/proto_test.go | 2 +- http/codegen/example_server_test.go | 4 ++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/codegen/example/example_server_test.go b/codegen/example/example_server_test.go index 6d4830f857..4304a8e7d5 100644 --- a/codegen/example/example_server_test.go +++ b/codegen/example/example_server_test.go @@ -26,8 +26,8 @@ func init() { func compareOrUpdateGolden(t *testing.T, code, golden string) { t.Helper() if updateGolden { - require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0755)) - require.NoError(t, os.WriteFile(golden, []byte(code), 0644)) + require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0750)) + require.NoError(t, os.WriteFile(golden, []byte(code), 0640)) return } data, err := os.ReadFile(golden) @@ -68,14 +68,7 @@ func TestExampleServerFiles(t *testing.T) { } code := codegen.FormatTestCode(t, "package foo\n"+buf.String()) golden := filepath.Join("testdata", "server-"+c.Name+".golden") - if updateGolden { - require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0755)) - require.NoError(t, os.WriteFile(golden, []byte(code), 0644)) - return - } - data, err := os.ReadFile(golden) - require.NoError(t, err) - assert.Equal(t, string(data), code) + compareOrUpdateGolden(t, code, golden) }) } } diff --git a/grpc/codegen/example_server_test.go b/grpc/codegen/example_server_test.go index 955ac4405f..f26011962f 100644 --- a/grpc/codegen/example_server_test.go +++ b/grpc/codegen/example_server_test.go @@ -25,8 +25,8 @@ func init() { func compareOrUpdateGolden(t *testing.T, code, golden string) { t.Helper() if updateGolden { - require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0755)) - require.NoError(t, os.WriteFile(golden, []byte(code), 0644)) + require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0750)) + require.NoError(t, os.WriteFile(golden, []byte(code), 0640)) return } data, err := os.ReadFile(golden) diff --git a/grpc/codegen/proto_test.go b/grpc/codegen/proto_test.go index 19051d7d22..d3441e4119 100644 --- a/grpc/codegen/proto_test.go +++ b/grpc/codegen/proto_test.go @@ -47,7 +47,7 @@ func TestProtoFiles(t *testing.T) { if runtime.GOOS == "windows" { code = strings.ReplaceAll(code, "\r\n", "\n") } - assert.Equal(t, code, c.Code) + assert.Equal(t, c.Code, code) fpath := codegen.CreateTempFile(t, code) assert.NoError(t, protoc(fpath, nil), "error occurred when compiling proto file %q", fpath) }) diff --git a/http/codegen/example_server_test.go b/http/codegen/example_server_test.go index 6754987e3f..4a3138bcff 100644 --- a/http/codegen/example_server_test.go +++ b/http/codegen/example_server_test.go @@ -27,8 +27,8 @@ func init() { func compareOrUpdateGolden(t *testing.T, code, golden string) { t.Helper() if updateGolden { - require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0755)) - require.NoError(t, os.WriteFile(golden, []byte(code), 0644)) + require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0750)) + require.NoError(t, os.WriteFile(golden, []byte(code), 0640)) return } data, err := os.ReadFile(golden)