Skip to content

Commit

Permalink
Fix Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AtakanColakSoftwire committed Jun 2, 2022
1 parent 82507a6 commit 268cc15
Showing 1 changed file with 29 additions and 40 deletions.
69 changes: 29 additions & 40 deletions mockSchemaRegistryClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,32 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

/*
We are going to test the client meant to be used for testing
*/

var srClient MockSchemaRegistryClient
var schema = "{ " +
"\"type\": \"record\", " +
"\"namespace\": \"com.mycorp.mynamespace\", " +
"\"name\": \"value_cdc_fake_2\", " +
"\"doc\": \"Sample schema to help you get started.\", " +
"\"fields\": [ " +
"{ " +
"\"name\": \"aField\"," +
"\"type\": \"int\", " +
"\"doc\": \"The int type is a 32-bit signed integer.\" " +
"}" +
"]" +
"}"

var schema2 = "{ " +
"\"type\": \"record\", " +
"\"namespace\": \"com.mycorp.mynamespace\", " +
"\"name\": \"value_cdc_fake_2\", " +
"\"doc\": \"Sample schema to help you get started.\", " +
"\"fields\": [ " +
"{ " +
"\"name\": \"bField\"," +
"\"type\": \"int\", " +
"\"doc\": \"The int type is a 32-bit signed integer.\" " +
"}" +
"]" +
"}"

var schema3 = "\"string\""
var schema4 = "\"int\""
var schema = `{
"type": "record",
"namespace": "com.mycorp.mynamespace",
"name": "value_cdc_fake_2",
"doc": "Sample schema to help you get started.",
"fields": [ { "name": "aField", "type": "int", "doc": "The int type is a 32-bit signed integer."}]
}`

var schema2 = `{
"type": "record",
"namespace": "com.mycorp.mynamespace",
"name": "value_cdc_fake_2",
"doc": "Sample schema to help you get started.",
"fields": [ { "name": "bField", "type": "int", "doc": "The int type is a 32-bit signed integer."}]
}`

var schema3 = `"string"`
var schema4 = `"int"`

/*
We will use init to register some schemas to run our test with.
Expand Down Expand Up @@ -71,22 +60,22 @@ func TestMockSchemaRegistryClient_CreateSchema(t *testing.T) {
By virtue of this test, we also test MockSchemaRegistryClient.GetSchema
*/
schemaReg1, _ := srClient.GetSchema(1)
assert.Equal(t, schema, schemaReg1.schema)
require.JSONEq(t, schema, schemaReg1.schema)
assert.Equal(t, 1, schemaReg1.version)
schemaReg2, _ := srClient.GetSchema(2)
assert.Equal(t, schema, schemaReg2.schema)
require.JSONEq(t, schema, schemaReg2.schema)
assert.Equal(t, 1, schemaReg2.version)
schemaReg3, _ := srClient.GetSchema(3)
assert.Equal(t, schema2, schemaReg3.schema)
require.JSONEq(t, schema2, schemaReg3.schema)
assert.Equal(t, 2, schemaReg3.version)
schemaReg4, _ := srClient.GetSchema(4)
assert.Equal(t, schema2, schemaReg4.schema)
require.JSONEq(t, schema2, schemaReg4.schema)
assert.Equal(t, 2, schemaReg4.version)
schemaReg5, _ := srClient.GetSchema(5)
assert.Equal(t, schema3, schemaReg5.schema)
require.JSONEq(t, schema3, schemaReg5.schema)
assert.Equal(t, 1, schemaReg5.version)
schemaReg6, _ := srClient.GetSchema(6)
assert.Equal(t, schema4, schemaReg6.schema)
require.JSONEq(t, schema4, schemaReg6.schema)
assert.Equal(t, 2, schemaReg6.version)

// Test registering already registered schema
Expand All @@ -105,15 +94,15 @@ func TestMockSchemaRegistryClient_GetLatestSchema(t *testing.T) {
fmt.Println(err.Error())
t.Fail()
} else {
assert.Equal(t, schema2, latest.schema)
require.JSONEq(t, schema2, latest.schema)
}

latest, err = srClient.GetLatestSchema("test1_arb")
if err != nil {
fmt.Println(err.Error())
t.Fail()
} else {
assert.Equal(t, schema4, latest.schema)
require.JSONEq(t, schema4, latest.schema)
}
}

Expand All @@ -136,10 +125,10 @@ func TestMockSchemaRegistryClient_GetSchemaVersions(t *testing.T) {

func TestMockSchemaRegistryClient_GetSchemaByVersion(t *testing.T) {
oldVersion, _ := srClient.GetSchemaByVersion("test1-value", 1)
assert.Equal(t, schema, oldVersion.schema)
require.JSONEq(t, schema, oldVersion.schema)

oldVersion, _ = srClient.GetSchemaByVersion("test1_arb", 1)
assert.Equal(t, schema3, oldVersion.schema)
require.JSONEq(t, schema3, oldVersion.schema)
}

func TestMockSchemaRegistryClient_GetSubjects(t *testing.T) {
Expand Down

0 comments on commit 268cc15

Please sign in to comment.