Skip to content

Commit

Permalink
Added NR unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcosal committed Nov 29, 2024
1 parent 2a66a53 commit d0f46fc
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 0 deletions.
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) {
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/attempt.avsc"})
assert.NoError(t, err)

err = generate(&buf, testPackage, ns, fileDefinitions[0])
assert.NoError(t, err)
g.Assert(t, "attempt", buf.Bytes())
}
107 changes: 107 additions & 0 deletions cmd/avrogo/testdata/schema/attempt.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"heetchmeta": {
"version": 1
},
"name": "Attempt",
"namespace": "billing_and_charging.entities.v1",
"type": "record",
"fields": [
{
"doc": "PaymentMethod is the payment method with which the passenger attempts to pay the ride. When the billing and charging phase starts, the payment method in the initial attempt will be the one selected during the ordering phase.",
"name": "PaymentMethod",
"type": {
"default": "UNSPECIFIED",
"doc": "PaymentMethod is the currently supported payment method a.k.a. payment mode. More payment methods will be supported in the future. Be aware that this enum doesn't support deprecated payment methods, as it will be used for new data. Therefore, it doesn't include symbols that might be present in HistoricalPaymentMethod. When referencing this entity from an event schema, make sure to either use a complex type or to set a default value on the field level.",
"heetchmeta": {
"skipRFC": true
},
"name": "PaymentMethod",
"namespace": "payment.entities.v1",
"symbols": [
"UNSPECIFIED",
"CASH",
"CARD",
"LYDIA",
"BURALISTE",
"STATIC_CHECKOUT",
"WAVE_CHECKOUT",
"MULTICAIXA_EXPRESS",
"WAVE"
],
"type": "enum"
}
},
{
"default": "UNSPECIFIED",
"name": "State",
"type": {
"name": "State",
"symbols": [
"UNSPECIFIED",
"STARTED",
"COMPLETED",
"FAILED",
"ADDED_BY_OPERATOR"
],
"type": "enum"
}
},
{
"default": null,
"doc": "THIS FIELD IS DEPRECATED and will be empty, as no consumer needs to react to / analyze the attempt details that are specific to a payment method. MulticaixaExpress will only be present when the payment method in the attempt is MULTICAIXA_EXPRESS. It contains the details that are specific to this payment method.",
"name": "MulticaixaExpress",
"status": "deprecated",
"type": [
"null",
{
"fields": [
{
"doc": "Phone number associated with the Multicaixa Express payment",
"name": "PhoneNumber",
"type": "string"
},
{
"default": "UNSPECIFIED",
"doc": "PaymentState holds the possible states of a Multicaixa Express payment. It should have been prefixed by the payment method but at the time it was introduced there was only one possible payment method and therefore no conflicts could happen. New attempt payment method states should be prefixed to avoid such conflicts. Future versions of this entity should have consistent naming if this field exists.",
"name": "PaymentState",
"type": {
"name": "PaymentState",
"symbols": [
"UNSPECIFIED",
"PENDING_PASSENGER_INFORMATION",
"CREATED",
"COMPLETED",
"EXPIRED",
"CANCELLED",
"REFUSED",
"FAILED"
],
"type": "enum"
}
}
],
"name": "MulticaixaExpress",
"type": "record"
}
]
},
{
"name": "StartedAt",
"type": {
"logicalType": "timestamp-micros",
"type": "long"
}
},
{
"default": null,
"name": "EndedAt",
"type": [
"null",
{
"logicalType": "timestamp-micros",
"type": "long"
}
]
}
]
}
228 changes: 228 additions & 0 deletions cmd/avrogo/testdata/schema/attempt.golden.go

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

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

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=
Loading

0 comments on commit d0f46fc

Please sign in to comment.