Skip to content

Commit

Permalink
Merge pull request #108 from k20human/schema-registry-url
Browse files Browse the repository at this point in the history
feat(url): Add new function `GetSchemaRegistryURL`
  • Loading branch information
riferrei authored Aug 8, 2024
2 parents 3dede03 + 3e62ea7 commit f2c6b0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mockSchemaRegistryClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package srclient
import (
"errors"
"fmt"
"github.com/linkedin/goavro/v2"
"net/url"
"regexp"
"sort"
"time"

"github.com/linkedin/goavro/v2"
)

// Compile-time interface check
Expand Down Expand Up @@ -203,6 +204,11 @@ func (mck *MockSchemaRegistryClient) GetSubjects() ([]string, error) {
return allSubjects, nil
}

// GetSchemaRegistryURL returns the URL of the schema registry
func (mck *MockSchemaRegistryClient) GetSchemaRegistryURL() string {
return mck.schemaRegistryURL
}

// GetSubjectsIncludingDeleted is not implemented and returns an error
func (mck *MockSchemaRegistryClient) GetSubjectsIncludingDeleted() ([]string, error) {
return nil, errNotImplemented
Expand Down
6 changes: 6 additions & 0 deletions schemaRegistryClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ISchemaRegistryClient interface {
GetSchemaVersions(subject string) ([]int, error)
GetSubjectVersionsById(schemaID int) (SubjectVersionResponse, error)
GetSchemaByVersion(subject string, version int) (*Schema, error)
GetSchemaRegistryURL() string
CreateSchema(subject string, schema string, schemaType SchemaType, references ...Reference) (*Schema, error)
LookupSchema(subject string, schema string, schemaType SchemaType, references ...Reference) (*Schema, error)
ChangeSubjectCompatibilityLevel(subject string, compatibility CompatibilityLevel) (*CompatibilityLevel, error)
Expand Down Expand Up @@ -251,6 +252,11 @@ func CreateSchemaRegistryClientWithOptions(schemaRegistryURL string, client *htt
return NewSchemaRegistryClient(schemaRegistryURL, WithClient(client), WithSemaphoreWeight(int64(semaphoreWeight)))
}

// GetSchemaRegistryURL returns the URL of the Schema Registry
func (client *SchemaRegistryClient) GetSchemaRegistryURL() string {
return client.schemaRegistryURL
}

// ResetCache resets the schema caches to be able to get updated schemas.
func (client *SchemaRegistryClient) ResetCache() {
client.idSchemaCacheLock.Lock()
Expand Down
17 changes: 17 additions & 0 deletions schemaRegistryClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ func TestSchemaRegistryClient_GetSubjectVersionsById(t *testing.T) {
}
}

func TestSchemaRegistryClient_GetSchemaRegistryURL(t *testing.T) {
t.Parallel()
server, _ := mockServerFromSubjectVersionPairWithSchemaResponse(t, "test1-value", "latest", schemaResponse{
Subject: "test1",
Version: 1,
Schema: "payload",
ID: 1,
References: nil,
})

srClient := CreateSchemaRegistryClient(server.URL)
// when
actual := srClient.GetSchemaRegistryURL()
// then
assert.Equal(t, actual, server.URL)
}

func TestSchemaRegistryClient_JsonSchemaParses(t *testing.T) {
t.Parallel()
{
Expand Down

0 comments on commit f2c6b0f

Please sign in to comment.