diff --git a/mockSchemaRegistryClient.go b/mockSchemaRegistryClient.go index 9f18ab7..4669c69 100644 --- a/mockSchemaRegistryClient.go +++ b/mockSchemaRegistryClient.go @@ -27,11 +27,11 @@ type MockSchemaRegistryClient struct { // schemaRegistryURL is used to form errors schemaRegistryURL string - // schemaCache is a map of subject to a map of versions to the actual schema - schemaCache map[string]map[int]*Schema + // schemaVersions is a map of subject to a map of versions to the actual schema + schemaVersions map[string]map[int]*Schema - // idCache is a map of schema ID to the actual schema - idCache map[int]*Schema + // schemaIDs is a map of schema ID to the actual schema + schemaIDs map[int]*Schema // idCounter is used to generate unique IDs for each schema idCounter int @@ -41,8 +41,8 @@ type MockSchemaRegistryClient struct { func CreateMockSchemaRegistryClient(mockURL string) *MockSchemaRegistryClient { mockClient := &MockSchemaRegistryClient{ schemaRegistryURL: mockURL, - schemaCache: map[string]map[int]*Schema{}, - idCache: map[int]*Schema{}, + schemaVersions: map[string]map[int]*Schema{}, + schemaIDs: map[int]*Schema{}, } return mockClient @@ -74,9 +74,9 @@ func (mck *MockSchemaRegistryClient) SetSchema(id int, subject string, schema st return nil, errInvalidSchemaType } - resultFromSchemaCache, ok := mck.schemaCache[subject] + resultFromSchemaCache, ok := mck.schemaVersions[subject] if !ok { - return mck.generateVersion(id, subject, schema, schemaType, version), nil + return mck.generateVersion(id, subject, schema, schemaType, version) } // Verify if it's not the same schema as an existing version @@ -91,12 +91,12 @@ func (mck *MockSchemaRegistryClient) SetSchema(id int, subject string, schema st } } - return mck.generateVersion(id, subject, schema, schemaType, version), nil + return mck.generateVersion(id, subject, schema, schemaType, version) } // GetSchema Returns a Schema for the given ID func (mck *MockSchemaRegistryClient) GetSchema(schemaID int) (*Schema, error) { - thisSchema, ok := mck.idCache[schemaID] + thisSchema, ok := mck.schemaIDs[schemaID] if !ok { posErr := url.Error{ Op: "GET", @@ -134,7 +134,7 @@ func (mck *MockSchemaRegistryClient) GetSchemaVersions(subject string) ([]int, e // GetSchemaByVersion Returns the given Schema according to the passed in subject and version number func (mck *MockSchemaRegistryClient) GetSchemaByVersion(subject string, version int) (*Schema, error) { var schema *Schema - schemaVersionMap, ok := mck.schemaCache[subject] + schemaVersionMap, ok := mck.schemaVersions[subject] if !ok { posErr := url.Error{ Op: "GET", @@ -165,7 +165,7 @@ func (mck *MockSchemaRegistryClient) GetSchemaByVersion(subject string, version func (mck *MockSchemaRegistryClient) GetSubjects() ([]string, error) { var allSubjects []string - for subject := range mck.schemaCache { + for subject := range mck.schemaVersions { allSubjects = append(allSubjects, subject) } @@ -179,13 +179,13 @@ func (mck *MockSchemaRegistryClient) GetSubjectsIncludingDeleted() ([]string, er // DeleteSubject removes given subject from the cache func (mck *MockSchemaRegistryClient) DeleteSubject(subject string, _ bool) error { - delete(mck.schemaCache, subject) + delete(mck.schemaVersions, subject) return nil } // DeleteSubjectByVersion removes given subject's version from cache func (mck *MockSchemaRegistryClient) DeleteSubjectByVersion(subject string, version int, _ bool) error { - _, ok := mck.schemaCache[subject] + _, ok := mck.schemaVersions[subject] if !ok { posErr := url.Error{ Op: "DELETE", @@ -195,9 +195,9 @@ func (mck *MockSchemaRegistryClient) DeleteSubjectByVersion(subject string, vers return &posErr } - for schemaVersion := range mck.schemaCache[subject] { + for schemaVersion := range mck.schemaVersions[subject] { if schemaVersion == version { - delete(mck.schemaCache[subject], schemaVersion) + delete(mck.schemaVersions[subject], schemaVersion) return nil } } @@ -275,24 +275,30 @@ qualify for key/value subjects, it expects to have a `concrete subject` passed o */ // generateVersion the next version of the schema for the given subject, givenVersion can be set to -1 to generate one. -func (mck *MockSchemaRegistryClient) generateVersion(id int, subject string, schema string, schemaType SchemaType, givenVersion int) *Schema { - versions := mck.allVersions(subject) +func (mck *MockSchemaRegistryClient) generateVersion(id int, subject string, schema string, schemaType SchemaType, givenVersion int) (*Schema, error) { schemaVersionMap := map[int]*Schema{} currentVersion := 1 - // Determine if a version was given if givenVersion >= 0 { currentVersion = givenVersion - } else { - // Otherwise, determine if we need to generate one from existing versions - if len(versions) > 0 { - schemaVersionMap = mck.schemaCache[subject] + } + + // if existing versions are found, make sure to load in the version map + if existingMap := mck.schemaVersions[subject]; len(existingMap) > 0 { + schemaVersionMap = existingMap + + // If no version was given, and existing versions are found, +1 the new number from the latest version + if givenVersion <= 0 { + versions := mck.allVersions(subject) currentVersion = versions[len(versions)-1] + 1 } } - // Add a codec, required otherwise Codec() panics - codec, _ := goavro.NewCodec(schema) + // Add a codec, required otherwise Codec() panics and the mock registry is unusable + codec, err := goavro.NewCodec(schema) + if err != nil { + return nil, err + } schemaToRegister := &Schema{ id: id, @@ -303,16 +309,16 @@ func (mck *MockSchemaRegistryClient) generateVersion(id int, subject string, sch } schemaVersionMap[currentVersion] = schemaToRegister - mck.schemaCache[subject] = schemaVersionMap - mck.idCache[schemaToRegister.id] = schemaToRegister + mck.schemaVersions[subject] = schemaVersionMap + mck.schemaIDs[schemaToRegister.id] = schemaToRegister - return schemaToRegister + return schemaToRegister, nil } // allVersions returns all versions for a given subject, assumes it exists func (mck *MockSchemaRegistryClient) allVersions(subject string) []int { var versions []int - result, ok := mck.schemaCache[subject] + result, ok := mck.schemaVersions[subject] if ok { for version := range result { diff --git a/mockSchemaRegistryClient_test.go b/mockSchemaRegistryClient_test.go index 17937c4..7a1b58a 100644 --- a/mockSchemaRegistryClient_test.go +++ b/mockSchemaRegistryClient_test.go @@ -16,23 +16,23 @@ var ( ) func TestMockSchemaRegistryClient_CreateSchema_RegistersSchemaCorrectly(t *testing.T) { + t.Parallel() tests := map[string]struct { subject string schema string schemaType SchemaType - currentIdCounter int - existingSchemaCounter int + currentIdCounter int + existingSchemas map[int]string expectedSchema *Schema }{ - "new avro schema": { + "first avro schema": { subject: "cupcake", schema: testSchema1, schemaType: Avro, - currentIdCounter: 1, - existingSchemaCounter: 0, + currentIdCounter: 1, expectedSchema: &Schema{ id: 2, @@ -41,13 +41,15 @@ func TestMockSchemaRegistryClient_CreateSchema_RegistersSchemaCorrectly(t *testi schema: testSchema1, }, }, - "existing avro schema": { + "second avro schema": { subject: "bakery", schema: testSchema2, schemaType: Avro, - currentIdCounter: 6, - existingSchemaCounter: 10, + currentIdCounter: 6, + existingSchemas: map[int]string{ + 10: testSchema1, + }, expectedSchema: &Schema{ id: 7, @@ -56,13 +58,15 @@ func TestMockSchemaRegistryClient_CreateSchema_RegistersSchemaCorrectly(t *testi schema: testSchema2, }, }, - "new protobuf schema": { + "second protobuf schema": { subject: "bakery", schema: testSchema2, schemaType: protobuf, - currentIdCounter: 23, - existingSchemaCounter: 75, + currentIdCounter: 23, + existingSchemas: map[int]string{ + 75: testSchema1, + }, expectedSchema: &Schema{ id: 24, @@ -74,16 +78,18 @@ func TestMockSchemaRegistryClient_CreateSchema_RegistersSchemaCorrectly(t *testi } for name, testData := range tests { + testData := testData t.Run(name, func(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") registry.idCounter = testData.currentIdCounter // Add existing schemas - if testData.existingSchemaCounter > 0 { - registry.schemaCache[testData.subject] = map[int]*Schema{} - for i := 1; i <= testData.existingSchemaCounter; i++ { - registry.schemaCache[testData.subject][i] = new(Schema) + for version, schema := range testData.existingSchemas { + _, err := registry.SetSchema(-1, testData.subject, schema, testData.schemaType, version) + if err != nil { + t.Fatal(err) } } @@ -91,20 +97,21 @@ func TestMockSchemaRegistryClient_CreateSchema_RegistersSchemaCorrectly(t *testi schema, err := registry.CreateSchema(testData.subject, testData.schema, testData.schemaType) // Assert - if assert.Nil(t, err) { + if assert.NoError(t, err) { assert.Equal(t, testData.expectedSchema.id, schema.id) assert.Equal(t, testData.expectedSchema.version, schema.version) assert.Equal(t, testData.expectedSchema.schemaType, schema.schemaType) assert.Equal(t, testData.expectedSchema.schema, schema.schema) - assert.Equal(t, schema, registry.idCache[schema.id]) - assert.Equal(t, schema, registry.schemaCache[testData.subject][schema.version]) + assert.Equal(t, schema, registry.schemaIDs[schema.id]) + assert.Equal(t, schema, registry.schemaVersions[testData.subject][schema.version]) } }) } } func TestMockSchemaRegistryClient_SetSchema_RegistersSchemaCorrectly(t *testing.T) { + t.Parallel() tests := map[string]struct { subject string schema string @@ -112,18 +119,16 @@ func TestMockSchemaRegistryClient_SetSchema_RegistersSchemaCorrectly(t *testing. id int version int - existingSchemaCounter int + existingSchemas map[int]string expectedSchema *Schema }{ - "new avro schema": { + "first avro schema": { subject: "cupcake", schema: testSchema1, schemaType: Avro, id: 52, - version: -1, - - existingSchemaCounter: 0, + version: -1, // Ensures it's generated expectedSchema: &Schema{ id: 52, @@ -132,34 +137,34 @@ func TestMockSchemaRegistryClient_SetSchema_RegistersSchemaCorrectly(t *testing. schema: testSchema1, }, }, - "existing avro schema": { + "second avro schema": { subject: "bakery", schema: testSchema2, schemaType: Avro, id: 7, - version: -1, + version: -1, // Ensures it's generated - existingSchemaCounter: 10, + existingSchemas: map[int]string{ + 1: testSchema1, + }, expectedSchema: &Schema{ id: 7, - version: 11, + version: 2, schemaType: &avroType, schema: testSchema2, }, }, - "new protobuf schema": { + "first protobuf schema": { subject: "bakery", schema: testSchema2, schemaType: Protobuf, id: 24, - version: -1, - - existingSchemaCounter: 75, + version: -1, // Ensures it's generated expectedSchema: &Schema{ id: 24, - version: 76, + version: 1, schemaType: &protobuf, schema: testSchema2, }, @@ -181,15 +186,17 @@ func TestMockSchemaRegistryClient_SetSchema_RegistersSchemaCorrectly(t *testing. } for name, testData := range tests { + testData := testData t.Run(name, func(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") // Add existing schemas - if testData.existingSchemaCounter > 0 { - registry.schemaCache[testData.subject] = map[int]*Schema{} - for i := 1; i <= testData.existingSchemaCounter; i++ { - registry.schemaCache[testData.subject][i] = new(Schema) + for version, schema := range testData.existingSchemas { + _, err := registry.SetSchema(-1, testData.subject, schema, testData.schemaType, version) + if err != nil { + t.Fatal(err) } } @@ -197,20 +204,21 @@ func TestMockSchemaRegistryClient_SetSchema_RegistersSchemaCorrectly(t *testing. schema, err := registry.SetSchema(testData.id, testData.subject, testData.schema, testData.schemaType, testData.version) // Assert - if assert.Nil(t, err) { + if assert.NoError(t, err) { assert.Equal(t, testData.expectedSchema.id, schema.id) assert.Equal(t, testData.expectedSchema.version, schema.version) assert.Equal(t, testData.expectedSchema.schemaType, schema.schemaType) assert.Equal(t, testData.expectedSchema.schema, schema.schema) - assert.Equal(t, schema, registry.idCache[schema.id]) - assert.Equal(t, schema, registry.schemaCache[testData.subject][schema.version]) + assert.Equal(t, schema, registry.schemaIDs[schema.id]) + assert.Equal(t, schema, registry.schemaVersions[testData.subject][schema.version]) } }) } } func TestMockSchemaRegistryClient_SetSchema_CorrectlyUpdatesIdCounter(t *testing.T) { + t.Parallel() tests := map[string]struct { currentId int newId int @@ -234,7 +242,9 @@ func TestMockSchemaRegistryClient_SetSchema_CorrectlyUpdatesIdCounter(t *testing } for name, testData := range tests { + testData := testData t.Run(name, func(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") registry.idCounter = testData.currentId @@ -249,6 +259,7 @@ func TestMockSchemaRegistryClient_SetSchema_CorrectlyUpdatesIdCounter(t *testing } func TestMockSchemaRegistryClient_CreateSchema_ReturnsErrorOnInvalidSchemaType(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -261,10 +272,11 @@ func TestMockSchemaRegistryClient_CreateSchema_ReturnsErrorOnInvalidSchemaType(t } func TestMockSchemaRegistryClient_CreateSchema_ReturnsErrorOnDuplicateSchema(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache["cupcake"] = map[int]*Schema{ + registry.schemaVersions["cupcake"] = map[int]*Schema{ 23: { schema: "{}", }, @@ -279,12 +291,13 @@ func TestMockSchemaRegistryClient_CreateSchema_ReturnsErrorOnDuplicateSchema(t * } func TestMockSchemaRegistryClient_GetSchema_ReturnsSchema(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") schema := &Schema{} - registry.idCache = map[int]*Schema{ + registry.schemaIDs = map[int]*Schema{ 234: schema, } @@ -297,6 +310,7 @@ func TestMockSchemaRegistryClient_GetSchema_ReturnsSchema(t *testing.T) { } func TestMockSchemaRegistryClient_GetSchema_ReturnsErrOnNotFound(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -310,6 +324,7 @@ func TestMockSchemaRegistryClient_GetSchema_ReturnsErrOnNotFound(t *testing.T) { } func TestMockSchemaRegistryClient_GetLatestSchema_ReturnsErrorOn0SchemaVersions(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -322,6 +337,7 @@ func TestMockSchemaRegistryClient_GetLatestSchema_ReturnsErrorOn0SchemaVersions( } func TestMockSchemaRegistryClient_GetLatestSchema_ReturnsExpectedSchema(t *testing.T) { + t.Parallel() tests := map[string]struct { subject string existingSchemas map[int]*Schema @@ -344,10 +360,12 @@ func TestMockSchemaRegistryClient_GetLatestSchema_ReturnsExpectedSchema(t *testi } for name, testData := range tests { + testData := testData t.Run(name, func(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache[testData.subject] = testData.existingSchemas + registry.schemaVersions[testData.subject] = testData.existingSchemas // Act result, err := registry.GetLatestSchema(testData.subject) @@ -361,9 +379,10 @@ func TestMockSchemaRegistryClient_GetLatestSchema_ReturnsExpectedSchema(t *testi } func TestMockSchemaRegistryClient_GetSchemaVersions_ReturnsSchemaVersions(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache["cupcake"] = map[int]*Schema{ + registry.schemaVersions["cupcake"] = map[int]*Schema{ 1: {id: 1}, 2: {id: 2}, 3: {id: 3}, @@ -379,6 +398,7 @@ func TestMockSchemaRegistryClient_GetSchemaVersions_ReturnsSchemaVersions(t *tes } func TestMockSchemaRegistryClient_GetSchemaByVersion_ReturnsErrorOnSubjectNotFound(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -391,9 +411,10 @@ func TestMockSchemaRegistryClient_GetSchemaByVersion_ReturnsErrorOnSubjectNotFou } func TestMockSchemaRegistryClient_GetSchemaByVersion_ReturnsErrorOnSchemaNotFound(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache = map[string]map[int]*Schema{ + registry.schemaVersions = map[string]map[int]*Schema{ "cupcake": {}, } @@ -406,6 +427,7 @@ func TestMockSchemaRegistryClient_GetSchemaByVersion_ReturnsErrorOnSchemaNotFoun } func TestMockSchemaRegistryClient_GetSchemaByVersion_ReturnsSchema(t *testing.T) { + t.Parallel() tests := map[string]struct { subject string version int @@ -434,10 +456,12 @@ func TestMockSchemaRegistryClient_GetSchemaByVersion_ReturnsSchema(t *testing.T) } for name, testData := range tests { + testData := testData t.Run(name, func(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache[testData.subject] = testData.existingSchemas + registry.schemaVersions[testData.subject] = testData.existingSchemas // Act result, err := registry.GetSchemaByVersion(testData.subject, testData.version) @@ -451,9 +475,10 @@ func TestMockSchemaRegistryClient_GetSchemaByVersion_ReturnsSchema(t *testing.T) } func TestMockSchemaRegistryClient_GetSubjects_ReturnsAllSubjects(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache = map[string]map[int]*Schema{ + registry.schemaVersions = map[string]map[int]*Schema{ "1": {}, "2": {}, "3": {}, @@ -470,6 +495,7 @@ func TestMockSchemaRegistryClient_GetSubjects_ReturnsAllSubjects(t *testing.T) { } func TestMockSchemaRegistryClient_GetSubjectsIncludingDeleted_IsNotImplemented(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -482,8 +508,9 @@ func TestMockSchemaRegistryClient_GetSubjectsIncludingDeleted_IsNotImplemented(t } func TestMockSchemaRegistryClient_DeleteSubject_DeletesSubject(t *testing.T) { + t.Parallel() registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache = map[string]map[int]*Schema{ + registry.schemaVersions = map[string]map[int]*Schema{ "b": {}, } @@ -492,12 +519,13 @@ func TestMockSchemaRegistryClient_DeleteSubject_DeletesSubject(t *testing.T) { // Assert assert.Nil(t, err) - assert.Equal(t, map[string]map[int]*Schema{}, registry.schemaCache) + assert.Equal(t, map[string]map[int]*Schema{}, registry.schemaVersions) } func TestMockSchemaRegistryClient_DeleteSubjectByVersion_DeletesSubjectVersion(t *testing.T) { + t.Parallel() registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache = map[string]map[int]*Schema{ + registry.schemaVersions = map[string]map[int]*Schema{ "b": { 1: {id: 1}, 2: {id: 2}, @@ -510,12 +538,13 @@ func TestMockSchemaRegistryClient_DeleteSubjectByVersion_DeletesSubjectVersion(t // Assert assert.Nil(t, err) - if assert.NotNil(t, registry.schemaCache["b"]) { - assert.Nil(t, registry.schemaCache["b"][2]) + if assert.NotNil(t, registry.schemaVersions["b"]) { + assert.Nil(t, registry.schemaVersions["b"][2]) } } func TestMockSchemaRegistryClient_DeleteSubjectByVersion_ReturnsErrorOnSubjectNotFound(t *testing.T) { + t.Parallel() registry := CreateMockSchemaRegistryClient("http://localhost:8081") // Act @@ -526,8 +555,9 @@ func TestMockSchemaRegistryClient_DeleteSubjectByVersion_ReturnsErrorOnSubjectNo } func TestMockSchemaRegistryClient_DeleteSubjectByVersion_ReturnsErrorOnVersionNotFound(t *testing.T) { + t.Parallel() registry := CreateMockSchemaRegistryClient("http://localhost:8081") - registry.schemaCache = map[string]map[int]*Schema{ + registry.schemaVersions = map[string]map[int]*Schema{ "cupcake": { 1: {id: 1}, 3: {id: 3}, @@ -542,6 +572,7 @@ func TestMockSchemaRegistryClient_DeleteSubjectByVersion_ReturnsErrorOnVersionNo } func TestMockSchemaRegistryClient_ChangeSubjectCompatibilityLevel_IsNotImplemented(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -554,6 +585,7 @@ func TestMockSchemaRegistryClient_ChangeSubjectCompatibilityLevel_IsNotImplement } func TestMockSchemaRegistryClient_GetGlobalCompatibilityLevel_IsNotImplemented(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -566,6 +598,7 @@ func TestMockSchemaRegistryClient_GetGlobalCompatibilityLevel_IsNotImplemented(t } func TestMockSchemaRegistryClient_GetCompatibilityLevel_IsNotImplemented(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -578,6 +611,7 @@ func TestMockSchemaRegistryClient_GetCompatibilityLevel_IsNotImplemented(t *test } func TestMockSchemaRegistryClient_IsSchemaCompatible_IsNotImplemented(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") @@ -590,6 +624,7 @@ func TestMockSchemaRegistryClient_IsSchemaCompatible_IsNotImplemented(t *testing } func TestMockSchemaRegistryClient_LookupSchema_IsNotImplemented(t *testing.T) { + t.Parallel() // Arrange registry := CreateMockSchemaRegistryClient("http://localhost:8081") diff --git a/schemaRegistryClientIntegration_test.go b/schemaRegistryClientIntegration_test.go index d4a71c7..8b362d5 100644 --- a/schemaRegistryClientIntegration_test.go +++ b/schemaRegistryClientIntegration_test.go @@ -1,3 +1,4 @@ +//go:build integration // +build integration package srclient @@ -14,6 +15,7 @@ var srclientUrl string = os.Getenv(srclientUrlEnvName) var client *SchemaRegistryClient = CreateSchemaRegistryClient(srclientUrl) func TestGetSubjects(t *testing.T) { + t.Parallel() subjects, err := client.GetSubjects() if err != nil { t.Fatal(err.Error()) @@ -22,6 +24,7 @@ func TestGetSubjects(t *testing.T) { } func TestCreateSchema(t *testing.T) { + t.Parallel() subject := "LongList" schema := `{ "type": "record", diff --git a/schemaRegistryClient_test.go b/schemaRegistryClient_test.go index 754ff71..e291b83 100644 --- a/schemaRegistryClient_test.go +++ b/schemaRegistryClient_test.go @@ -23,6 +23,7 @@ func bodyToString(in io.ReadCloser) string { } func TestSchemaRegistryClient_CreateSchemaWithoutReferences(t *testing.T) { + t.Parallel() { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { @@ -112,6 +113,7 @@ func TestSchemaRegistryClient_CreateSchemaWithoutReferences(t *testing.T) { } func TestSchemaRegistryClient_LookupSchemaWithoutReferences(t *testing.T) { + t.Parallel() var errorCode int var errorMessage string { @@ -284,6 +286,7 @@ func TestSchemaRegistryClient_LookupSchemaWithoutReferences(t *testing.T) { } func TestSchemaRegistryClient_GetSchemaByIDWithReferences(t *testing.T) { + t.Parallel() { refs := []Reference{ {Name: "name1", Subject: "subject1", Version: 1}, @@ -350,6 +353,7 @@ func TestSchemaRegistryClient_GetSchemaByIDWithReferences(t *testing.T) { } func TestSchemaRegistryClient_GetSchemaByVersionWithReferences(t *testing.T) { + t.Parallel() { refs := []Reference{ {Name: "name1", Subject: "subject1", Version: 1}, @@ -416,6 +420,7 @@ func TestSchemaRegistryClient_GetSchemaByVersionWithReferences(t *testing.T) { } func TestSchemaRegistryClient_GetSchemaByVersionReturnsValueFromCache(t *testing.T) { + t.Parallel() { server, call := mockServerFromSubjectVersionPairWithSchemaResponse(t, "test1", "1", schemaResponse{ Subject: "test1", @@ -441,6 +446,7 @@ func TestSchemaRegistryClient_GetSchemaByVersionReturnsValueFromCache(t *testing } func TestSchemaRegistryClient_GetLatestSchemaReturnsValueFromCache(t *testing.T) { + t.Parallel() server, call := mockServerFromSubjectVersionPairWithSchemaResponse(t, "test1-value", "latest", schemaResponse{ Subject: "test1", Version: 1, @@ -464,6 +470,7 @@ func TestSchemaRegistryClient_GetLatestSchemaReturnsValueFromCache(t *testing.T) } func TestSchemaRegistryClient_GetSchemaType(t *testing.T) { + t.Parallel() { expectedSchemaType := Json server, call := mockServerFromSubjectVersionPairWithSchemaResponse(t, "test1-value", "latest", schemaResponse{ @@ -503,6 +510,7 @@ func TestSchemaRegistryClient_GetSchemaType(t *testing.T) { } func TestSchemaRegistryClient_JsonSchemaParses(t *testing.T) { + t.Parallel() { server, call := mockServerFromSubjectVersionPairWithSchemaResponse(t, "test1-value", "latest", schemaResponse{ Subject: "test1", @@ -543,6 +551,7 @@ func TestSchemaRegistryClient_JsonSchemaParses(t *testing.T) { } func TestNewSchema(t *testing.T) { + t.Parallel() const ( anId = 3 aSchema = "payload" @@ -604,69 +613,72 @@ func TestNewSchema(t *testing.T) { } func TestSchemaRequestMarshal(t *testing.T) { - tests := map[string]struct{ - schema string + t.Parallel() + tests := map[string]struct { + schema string schemaType SchemaType references []Reference - expected string + expected string }{ "avro": { - schema: `test2`, + schema: `test2`, schemaType: Avro, - expected: `{"schema":"test2"}`, + expected: `{"schema":"test2"}`, }, "protobuf": { - schema: `test2`, + schema: `test2`, schemaType: Protobuf, - expected: `{"schema":"test2","schemaType":"PROTOBUF"}`, + expected: `{"schema":"test2","schemaType":"PROTOBUF"}`, }, "json": { - schema: `test2`, + schema: `test2`, schemaType: Json, - expected: `{"schema":"test2","schemaType":"JSON"}`, + expected: `{"schema":"test2","schemaType":"JSON"}`, }, "avro-empty-ref": { - schema: `test2`, + schema: `test2`, schemaType: Avro, references: make([]Reference, 0), - expected: `{"schema":"test2"}`, + expected: `{"schema":"test2"}`, }, "protobuf-empty-ref": { - schema: `test2`, + schema: `test2`, schemaType: Protobuf, references: make([]Reference, 0), - expected: `{"schema":"test2","schemaType":"PROTOBUF"}`, + expected: `{"schema":"test2","schemaType":"PROTOBUF"}`, }, "json-empty-ref": { - schema: `test2`, + schema: `test2`, schemaType: Json, references: make([]Reference, 0), - expected: `{"schema":"test2","schemaType":"JSON"}`, + expected: `{"schema":"test2","schemaType":"JSON"}`, }, "avro-ref": { - schema: `test2`, + schema: `test2`, schemaType: Avro, references: []Reference{{Name: "name1", Subject: "subject1", Version: 1}}, - expected: `{"schema":"test2","references":[{"name":"name1","subject":"subject1","version":1}]}`, + expected: `{"schema":"test2","references":[{"name":"name1","subject":"subject1","version":1}]}`, }, "protobuf-ref": { - schema: `test2`, + schema: `test2`, schemaType: Protobuf, references: []Reference{{Name: "name1", Subject: "subject1", Version: 1}}, - expected: `{"schema":"test2","schemaType":"PROTOBUF","references":[{"name":"name1","subject":"subject1","version":1}]}`, + expected: `{"schema":"test2","schemaType":"PROTOBUF","references":[{"name":"name1","subject":"subject1","version":1}]}`, }, "json-ref": { - schema: `test2`, + schema: `test2`, schemaType: Json, references: []Reference{{Name: "name1", Subject: "subject1", Version: 1}}, - expected: `{"schema":"test2","schemaType":"JSON","references":[{"name":"name1","subject":"subject1","version":1}]}`, + expected: `{"schema":"test2","schemaType":"JSON","references":[{"name":"name1","subject":"subject1","version":1}]}`, }, } for name, testData := range tests { + testData := testData t.Run(name, func(t *testing.T) { + t.Parallel() schemaReq := schemaRequest{ - Schema: testData.schema, + Schema: testData.schema, SchemaType: testData.schemaType.String(), References: testData.references, }