-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for jsonnet functions and fix parseYAML. #195
Conversation
- funcs.go was missing tests for the jsonnet native functions, this PR adds some basic tests exercising some generic classses of arguments - `parseYAML` seems to have been doing one extra step of marshalling the YAML documents into JSON, which it probably shouldn't do and this PR removes the functionality. W.r.t. second point, the current implementation looks like manifestJsonFrom Yaml or similar -- is there any use case for that that would be worth adding it? Signed-off-by: Milan Plzik <[email protected]>
This should fix #194 . |
pkg/jsonnet/native/funcs.go
Outdated
return nil, err | ||
} | ||
ret = append(ret, jsonDoc) | ||
ret = append(ret, doc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this result in problems further down the line? Jsonnet expects the result of a native function to comply with the standard Go representation, that is:
bool, for JSON booleans
float64, for JSON numbers
string, for JSON strings
[]interface{}, for JSON arrays
map[string]interface{}, for JSON objects
nil for JSON null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we alreaday noticed this
Signed-off-by: Milan Plzik <[email protected]>
This normalizes YAML data to a form compatible with JSON -- that is, `int` gets turned into `float64` etc. Note: some cases this code still fails with: ``` evaluating jsonnet: unexpected end of JSON input ``` Interestingly enough, the same file (CRDs from cert-manager) fails when used from a jsonnet library for cert-manager, but succeeds when loaded from a dummy libsonnet file. Signed-off-by: Milan Plzik <[email protected]>
The `err` variable returned by `jsonnet.EvaluateFile` call was silently ignored, making tanka fail with mysterious ``` evaluating jsonnet: unexpected end of JSON input ``` This commit makes the code properly handle errors. Thanks to @sh0rez for a quick pointer. Signed-off-by: Milan Plzik <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
funcs.go was missing tests for the jsonnet native functions, this PR
adds some basic tests exercising some generic classses of arguments
parseYAML
seems to have been doing one extra step of marshalling theYAML documents into JSON, which it probably shouldn't do and this PR
removes the functionality.
W.r.t. second point, the current implementation looks like
manifestJsonFrom Yaml or similar -- is there any use case for that that
would be worth adding it?