-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid import of typeinfo when not necessary. Now based on given files…
… t… (#115) * Avoid import of typeinfo when not cessary. Now based on given files to generated * create shouldImportAvroTypeGen function * Add some tests * ♻️ Implement review ! * ♻️ Implement review ! * 🎉 Add fixed definition handling * 🚀 fix generation * 🚀 fix generation
- Loading branch information
Showing
2 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/actgardner/gogen-avro/v10/parser" | ||
"github.com/actgardner/gogen-avro/v10/schema" | ||
"testing" | ||
|
||
avro "github.com/actgardner/gogen-avro/v10/schema" | ||
qt "github.com/frankban/quicktest" | ||
) | ||
|
||
func TestShouldImportAvroTypeGen(t *testing.T) { | ||
var eventNameQualifiedName = schema.QualifiedName{Namespace: "EventName", Name: "EventName"} | ||
var eventNameAsRecordDefinition = schema.NewRecordDefinition(eventNameQualifiedName, []avro.QualifiedName{}, []*avro.Field{}, "", map[string]interface{}{}) | ||
var eventNameAsFixedFieldDefinition = schema.NewFixedDefinition(eventNameQualifiedName, []avro.QualifiedName{}, 142, map[string]interface{}{}) | ||
var modelDefinitionQualifiedName = schema.QualifiedName{Namespace: "ModelDefinition", Name: "ModelDefinition"} | ||
var modelAsEnumDefinition = schema.NewEnumDefinition(modelDefinitionQualifiedName, []avro.QualifiedName{}, []string{"", ""}, "", "defaultValue", map[string]interface{}{}) | ||
|
||
var shouldImportAvroTypeGenTests = []struct { | ||
testName string | ||
namespace *parser.Namespace | ||
definitions []schema.QualifiedName | ||
shouldImportAvroTypeGen bool | ||
}{ | ||
{ | ||
testName: "true-definition-only-present-in-namespace-and-is-record-type", | ||
namespace: &parser.Namespace{ | ||
Definitions: map[schema.QualifiedName]schema.Definition{ | ||
eventNameQualifiedName: eventNameAsRecordDefinition, | ||
}, | ||
}, | ||
definitions: []schema.QualifiedName{eventNameQualifiedName}, | ||
shouldImportAvroTypeGen: true, | ||
}, | ||
{ | ||
testName: "true-definition-only-present-in-namespace-and-is-fixed-type", | ||
namespace: &parser.Namespace{ | ||
Definitions: map[schema.QualifiedName]schema.Definition{ | ||
eventNameQualifiedName: eventNameAsFixedFieldDefinition, | ||
}, | ||
}, | ||
definitions: []schema.QualifiedName{eventNameQualifiedName}, | ||
shouldImportAvroTypeGen: true, | ||
}, | ||
{ | ||
testName: "true-definition-present-in-namespace-and-is-record-type", | ||
namespace: &parser.Namespace{ | ||
Definitions: map[schema.QualifiedName]schema.Definition{ | ||
eventNameQualifiedName: eventNameAsRecordDefinition, | ||
modelDefinitionQualifiedName: modelAsEnumDefinition, | ||
}, | ||
}, | ||
definitions: []schema.QualifiedName{eventNameQualifiedName}, | ||
shouldImportAvroTypeGen: true, | ||
}, | ||
{ | ||
testName: "false-definition-present-in-namespace-and-not-record-type", | ||
namespace: &parser.Namespace{ | ||
Definitions: map[schema.QualifiedName]schema.Definition{ | ||
eventNameQualifiedName: eventNameAsRecordDefinition, | ||
modelDefinitionQualifiedName: modelAsEnumDefinition, | ||
}, | ||
}, | ||
definitions: []schema.QualifiedName{modelDefinitionQualifiedName}, | ||
shouldImportAvroTypeGen: false, | ||
}, | ||
} | ||
|
||
c := qt.New(t) | ||
|
||
for _, test := range shouldImportAvroTypeGenTests { | ||
c.Run(test.testName, func(c *qt.C) { | ||
value := shouldImportAvroTypeGen(test.namespace, test.definitions) | ||
c.Assert(value, qt.Equals, test.shouldImportAvroTypeGen) | ||
}) | ||
} | ||
} |