Skip to content

Commit

Permalink
Handle Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael committed Jun 26, 2024
1 parent d83b7ee commit c567e6b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
13 changes: 3 additions & 10 deletions codegen/example/example_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}
}
4 changes: 2 additions & 2 deletions grpc/codegen/example_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion grpc/codegen/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
4 changes: 2 additions & 2 deletions http/codegen/example_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c567e6b

Please sign in to comment.