Giter Club home page Giter Club logo

randomize's People

Contributors

aarondl avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

admpub isgasho

randomize's Issues

Nullable types are not supported

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.