Skip to content

Commit

Permalink
Merge branch 'main' into ebracci-protocol-original-string
Browse files Browse the repository at this point in the history
  • Loading branch information
elia-bracci-hs authored Oct 20, 2023
2 parents c192f00 + 50a7897 commit 3c6fbb7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (p *Protocol) OriginalString() string {
return p.originalString
}

// Types returns the types of the protocol.
func (p *Protocol) Types() []NamedSchema {
return p.types
}

// String returns the canonical form of the protocol.
func (p *Protocol) String() string {
types := ""
Expand Down
14 changes: 14 additions & 0 deletions protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,17 @@ func TestParseProtocolFile_InvalidPath(t *testing.T) {

assert.Error(t, err)
}

func TestParseProtocol_Types(t *testing.T) {
protocol, err := avro.ParseProtocolFile("testdata/echo.avpr")

wantPing := `{"name":"org.hamba.avro.Ping","type":"record","fields":[{"name":"timestamp","type":"long"},{"name":"text","type":"string"}]}`
wantPong := `{"name":"org.hamba.avro.Pong","type":"record","fields":[{"name":"timestamp","type":"long"},{"name":"ping","type":"org.hamba.avro.Ping"}]}`
wantPongError := `{"name":"org.hamba.avro.PongError","type":"error","fields":[{"name":"timestamp","type":"long"},{"name":"reason","type":"string"}]}`
wantLen := 3
require.NoError(t, err)
assert.Equal(t, wantLen, len(protocol.Types()))
assert.Equal(t, wantPing, protocol.Types()[0].String())
assert.Equal(t, wantPong, protocol.Types()[1].String())
assert.Equal(t, wantPongError, protocol.Types()[2].String())
}

0 comments on commit 3c6fbb7

Please sign in to comment.