Skip to content

Commit

Permalink
Bugfix #64 (#67)
Browse files Browse the repository at this point in the history
* add test to show the panic manifesting

* fix array index out of bounds panic in mock schema registry client
  • Loading branch information
topliceanu authored Dec 29, 2021
1 parent 1639e7f commit 8edc580
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mockSchemaRegistryClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (mck MockSchemaRegistryClient) GetLatestSchema(subject string) (*Schema, er
if getSchemaVersionErr != nil {
return nil, getSchemaVersionErr
}

if len(versions) == 0 {
return nil, errors.New("Subject not found")
}
latestVersion := versions[len(versions)-1]
thisSchema, err := mck.GetSchemaByVersion(subject, latestVersion)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions mockSchemaRegistryClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ func TestMockSchemaRegistryClient_GetLatestSchema(t *testing.T) {
}
}

func TestMockSchemaRegistryClient_GetLatestSchema_WhenNoSchemaRegistered(t *testing.T) {
localClient := CreateMockSchemaRegistryClient("")
var err error
assert.NotPanics(t, func() {
_, err = localClient.GetLatestSchema("some-innexistent-schema-subject")
})
assert.EqualError(t, err, "Subject not found")
}

func TestMockSchemaRegistryClient_GetSchemaVersions(t *testing.T) {
versions, _ := srClient.GetSchemaVersions("test1-key")
assert.Equal(t, 2, len(versions))
Expand Down

0 comments on commit 8edc580

Please sign in to comment.