volatiletech / randomize Goto Github PK
View Code? Open in Web Editor NEWSupport library for sqlboiler
License: BSD 3-Clause "New" or "Revised" License
Support library for sqlboiler
License: BSD 3-Clause "New" or "Revised" License
When trying to generate tests for sqlboiler (a module that uses this module) I have encountered this error:
Unable to randomize ObjName object: unsupported type: models.NullEnumType
After debugging the issue, the problem seems to be that Null types generated by sqlboiler are not supported by this repo.
For example, enum.NullEnumType
will not get randomized.
In randomize.go#L143
(link) we see:
if kind == reflect.Struct {
if shouldBeNull {
value = getStructNullValue(s, fieldType, typ)
} else {
value = getStructRandValue(s, fieldType, typ)
}
} else {
...
Because the type is actually a struct (enum.NullEnumType
) we get True and continue.
Based on shouldBeNull
the relevant function is called.
Both functions support only type Date
and doesn't "try" to resolve nullable structs (as it probably should, null types are supported by sqlboiler).
func getStructRandValue(s *Seed, fieldType string, typ reflect.Type) interface{} {
if typ == typeTime {
return Date(s.NextInt)
}
return nil
}
Adding a check for structs of type nullable will solve this issue.
Optional solution:
In the getStructRandValue
/getStructNullValue
add a simple check that verifies if the struct is of type nullable (using isValid
or any other identifier).
If it is of this type, try to resolve the type of the value member of the struct.
In our case, it will be EnumType.
Then call the regular function getVariableRandValue
/getVariableZeroValue
for this member and get a valid random value.
That way, most of the newly created Nullable-EnumTypes will be supported.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.