Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/avrogo/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"bytes"
"encoding/json"
"fmt"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"io"
"regexp"
"sort"
"strconv"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/actgardner/gogen-avro/v10/parser"
"github.com/actgardner/gogen-avro/v10/schema"
)
Expand Down Expand Up @@ -425,7 +426,7 @@ func (gc *generateContext) defaultFuncLiteral(v interface{}, t schema.AvroType)
func goName(s string) (string, error) {
lastIndex := strings.LastIndex(s, ".")
name := s[lastIndex+1:]
name = cases.Title(language.Und).String(strings.Trim(name, "_"))
name = cases.Title(language.Und, cases.NoLower).String(strings.Trim(name, "_"))
if !isExportedGoIdentifier(name) {
return "", fmt.Errorf("cannot form an exported Go identifier from %q", s)
}
Expand Down
17 changes: 17 additions & 0 deletions cmd/avrogo/generate_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package main

import (
"bytes"
"github.com/actgardner/gogen-avro/v10/parser"
"github.com/actgardner/gogen-avro/v10/schema"
"github.com/sebdah/goldie/v2"
"github.com/stretchr/testify/assert"
"testing"

avro "github.com/actgardner/gogen-avro/v10/schema"
Expand Down Expand Up @@ -75,3 +78,17 @@ func TestShouldImportAvroTypeGen(t *testing.T) {
})
}
}

func TestGenerate(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

fixtureDir := "testdata/schema"
g := goldie.New(t, goldie.WithFixtureDir(fixtureDir), goldie.WithNameSuffix(".golden.go"))

var buf bytes.Buffer
testPackage := "dummy"
ns, fileDefinitions, err := parseFiles([]string{"testdata/schema/object.avsc"})
assert.NoError(t, err)

err = generate(&buf, testPackage, ns, fileDefinitions[0])
assert.NoError(t, err)
g.Assert(t, "object", buf.Bytes())
}
2 changes: 1 addition & 1 deletion cmd/avrogo/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func defName(def schema.Definition) string {
}

func symbolName(e *schema.EnumDefinition, symbol string) string {
return defName(e) + cases.Title(language.Und).String(symbol)
return defName(e) + cases.Title(language.Und, cases.NoLower).String(symbol)
}

func quote(s string) string {
Expand Down
15 changes: 15 additions & 0 deletions cmd/avrogo/testdata/schema/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module dummy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go.mod is to prevent generated code from being scanned as part of avro code


go 1.23

require (
github.com/google/uuid v1.6.0
github.com/heetch/avro v0.4.6-0.20241128170218-20b562ce498f
github.com/heetch/galaxy-go/v2 v2.24.0
)

require github.com/actgardner/gogen-avro/v10 v10.2.1 // indirect

replace (
github.com/heetch/avro => ../../../..
)
8 changes: 8 additions & 0 deletions cmd/avrogo/testdata/schema/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/actgardner/gogen-avro/v10 v10.2.1 h1:z3pOGblRjAJCYpkIJ8CmbMJdksi4rAhaygw0dyXZ930=
github.com/actgardner/gogen-avro/v10 v10.2.1/go.mod h1:QUhjeHPchheYmMDni/Nx7VB0RsT/ee8YIgGY/xpEQgQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/heetch/avro v0.4.6-0.20241128170218-20b562ce498f h1:iK4+HtIuNeOEJsVBRMOmmEl9mVbnhbf2MYbvzvK22+E=
github.com/heetch/avro v0.4.6-0.20241128170218-20b562ce498f/go.mod h1:gxf9GnbjTXmWmqxhdNbAMcZCjpye7RV5r9t3Q0dL6ws=
github.com/heetch/galaxy-go/v2 v2.24.0 h1:qn5wIMWpFSogzQQ2SzvVoUrd1sc74U9xjbsjmbkWils=
github.com/heetch/galaxy-go/v2 v2.24.0/go.mod h1:VSyZlEylS5T7UDPlaC9fjVvMz5qo0sh3JyHjajWyh9E=
46 changes: 46 additions & 0 deletions cmd/avrogo/testdata/schema/object.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"heetchmeta": {
"version": 1
},
"name": "Object",
"namespace": "ns",
"type": "record",
"fields": [
{
"doc": "Child1",
"name": "Child1",
"type": {
"default": "UNSPECIFIED",
"doc": "doc",
"heetchmeta": {
"skipRFC": true
},
"name": "Child1",
"namespace": "subns",
"symbols": [
"UNSPECIFIED",
"VALUE1",
"VALUE2",
"VALUE_EXTRA_1",
"VALUE_EXTRA_2"
],
"type": "enum"
}
},
{
"default": "UNSPECIFIED",
"name": "Child2",
"type": {
"name": "Child2",
"symbols": [
"UNSPECIFIED",
"STARTED",
"COMPLETED",
"FAILED",
"ADDED_BY_OPERATOR"
],
"type": "enum"
}
}
]
}
135 changes: 135 additions & 0 deletions cmd/avrogo/testdata/schema/object.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ require (
github.com/kr/pretty v0.3.0
github.com/linkedin/goavro/v2 v2.11.1
github.com/rogpeppe/go-internal v1.9.0
github.com/sebdah/goldie/v2 v2.5.5
github.com/stretchr/testify v1.7.1
golang.org/x/text v0.3.0
gopkg.in/httprequest.v1 v1.2.1
gopkg.in/retry.v1 v1.0.3
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
golang.org/x/net v0.0.0-20200505041828-1ed23360d12c // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/errgo.v1 v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
github.com/actgardner/gogen-avro/v10 v10.2.1 h1:z3pOGblRjAJCYpkIJ8CmbMJdksi4rAhaygw0dyXZ930=
github.com/actgardner/gogen-avro/v10 v10.2.1/go.mod h1:QUhjeHPchheYmMDni/Nx7VB0RsT/ee8YIgGY/xpEQgQ=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
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/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y=
Expand Down Expand Up @@ -33,13 +35,22 @@ github.com/linkedin/goavro/v2 v2.11.1 h1:4cuAtbDfqkKnBXp9E+tRkIJGa6W6iAjwonwt8O1
github.com/linkedin/goavro/v2 v2.11.1/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/rogpeppe/clock v0.0.0-20190514195947-2896927a307a h1:3QH7VyOaaiUHNrA9Se4YQIRkDTCw1EJls9xTUCaCeRM=
github.com/rogpeppe/clock v0.0.0-20190514195947-2896927a307a/go.mod h1:4r5QyqhjIWCcK8DO4KMclc5Iknq5qVBAlbYYzAbUScQ=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sebdah/goldie/v2 v2.5.5 h1:rx1mwF95RxZ3/83sdS4Yp7t2C5TCokvWP4TBRbAyEWY=
github.com/sebdah/goldie/v2 v2.5.5/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
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.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -76,4 +87,6 @@ gopkg.in/retry.v1 v1.0.3 h1:a9CArYczAVv6Qs6VGoLMio99GEs7kY9UzSF9+LD+iGs=
gopkg.in/retry.v1 v1.0.3/go.mod h1:FJkXmWiMaAo7xB+xhvDF59zhfjDWyzmyAxiT4dB688g=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading