Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Types methods to Protocol #315

Merged
merged 4 commits into from
Oct 20, 2023
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
5 changes: 5 additions & 0 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func (p *Protocol) Hash() string {
return p.hash
}

// 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 @@ -190,3 +190,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())
}
Loading