Created
July 29, 2024 17:09
-
-
Save lovromazgon/50ecf204e65f7d1ad080fbd0fa7d52fb to your computer and use it in GitHub Desktop.
Showcase of bug in hamba library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module hamba.test | |
go 1.22.3 | |
require github.com/hamba/avro/v2 v2.23.0 | |
require ( | |
github.com/json-iterator/go v1.1.12 // indirect | |
github.com/mitchellh/mapstructure v1.5.0 // indirect | |
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | |
github.com/modern-go/reflect2 v1.0.2 // indirect | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | |
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | |
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | |
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | |
github.com/hamba/avro/v2 v2.23.0 h1:DYWz6UqNCi21JflaZlcwNfW+rK+D/CwnrWWJtfmO4vw= | |
github.com/hamba/avro/v2 v2.23.0/go.mod h1:7vDfy/2+kYCE8WUHoj2et59GTv0ap7ptktMXu0QHePI= | |
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= | |
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= | |
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= | |
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= | |
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | |
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= | |
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | |
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= | |
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= | |
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | |
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | |
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | |
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | |
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | |
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | |
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | |
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hambatest | |
import ( | |
"bytes" | |
"fmt" | |
"math" | |
"testing" | |
"github.com/hamba/avro/v2" | |
) | |
func TestHamba_Int(t *testing.T) { | |
var ( | |
in = math.MaxInt32 + 1 // value exceeds the range of int32 | |
out int | |
) | |
err := encodeDecode("int", in, &out) | |
if err != nil { | |
t.Fatalf("unexpected error: %v", err) | |
} | |
if in != out { | |
t.Logf("expected %v, got %v", in, out) | |
t.Fail() | |
} | |
// try with "long" | |
err = encodeDecode("long", in, &out) | |
if err != nil { | |
t.Fatalf("unexpected error: %v", err) | |
} | |
if in != out { | |
t.Logf("expected %v, got %v", in, out) | |
t.Fail() | |
} | |
} | |
func encodeDecode(schema string, in, out any) error { | |
buf := bytes.NewBuffer(nil) | |
enc, err := avro.NewEncoder(schema, buf) | |
if err != nil { | |
return fmt.Errorf("failed to create encoder: %w", err) | |
} | |
err = enc.Encode(in) | |
if err != nil { | |
return fmt.Errorf("failed to encode: %w", err) | |
} | |
dec, err := avro.NewDecoder(schema, buf) | |
if err != nil { | |
return fmt.Errorf("failed to create decoder: %w", err) | |
} | |
err = dec.Decode(out) | |
if err != nil { | |
return fmt.Errorf("failed to decode: %w", err) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment