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

feat(url): Add new function GetSchemaRegistryURL #108

Merged
merged 1 commit into from
Aug 8, 2024
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
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
Loading