Updates on JSonnet testing

4 views
Skip to first unread message

Joseph Wilkicki

unread,
Dec 11, 2025, 2:06:14 PM (6 days ago) Dec 11
to Jsonnet
Hey folks,

I'm working on using Jsonnet through Grafana Tanka to handle Kubernetes configurations.  Up until now, I've been using Terraform for some things and it isn't exactly excellent for Kubernetes stuff.

One thing I was used to, however, was a range of options for testing my code. I've seen a few different options for Jsonnet but they all seem very old and searching in this forum, I don't see a lot of recent discussion on this.

I've gotten testonnet to work but one puzzle I've had is how to do negative tests; things like: passing invalid values to functions and verifying my validation logic is correct.  This appears to be a problem because problems of this type appear to end up in errors or asserts and there seems to be no mechanism in Jsonnet to catch them. That would seem to make it hard to write a test that says "expect Jsonnet to throw an error for this value".

Has there been any evolution on this topic?  Or is it possible that I need to evolve my design understanding to do this a different way? 

At present, my only other thought was using something like Terratest with golang to invoke jsonnet or tanka from the outside and then catching the errors from the interpreter to check for negative test cases and validating the output for positive test cases.  I would have liked to do this all in one language since we've already done Terraform/Terratest and it has been a common complaint from my team about having to deal with two languages to write code and test it effectively.

Thank you in advance for any thoughts on the topic.

Jeroen Op 't Eynde

unread,
Dec 15, 2025, 5:32:24 PM (2 days ago) Dec 15
to Joseph Wilkicki, Jsonnet
Hi Joseph

Nice to see testonnet getting mentioned, I wrote that. :)

Testing whether an assertion works is indeed a bit odd to do from
within jsonnet. Depending on the situation it might be useful to have
a function that the assertion calls and then write a unit test for
that function instead.

Another pattern is testing with golden files, this is used in the
jsonnet project itself:
https://github.com/google/jsonnet/blob/master/test_suite/README.md I
don't know Terratest, based on your description it seems like a
similar pattern.

Cheers
> --
> You received this message because you are subscribed to the Google Groups "Jsonnet" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/jsonnet/5f15b9fc-d803-45b7-a628-36fdb707bd74n%40googlegroups.com.



--
Jeroen Op 't Eynde
Reply all
Reply to author
Forward
0 new messages