Skip to content

Validation of the generated template #1681

Discussion options

You must be logged in to vote

Hi @jeremych1000, I've transferred this to a Discussion since this wasn't a bug report or feature request.

Here's a sample template that will do what I think you're looking for:

{{ $nameKind := test.Kind .tenant.name -}}
{{ $acctKind := test.Kind .tenant.account -}}
{{ eq "string" $nameKind | test.Assert (printf "name must be a string, but was a %s" $nameKind) -}}
{{ eq "int" $acctKind | test.Assert (printf "account must be an int, but was a %s" $acctKind) -}}

Given an (invalid) input of:

{ 
  "tenant": {
      "name": "foobar",
      "account": true
  }
}

This will fail as follows:

$ gomplate -c .=in.json -f t.tmpl
09:21:12 ERR error="renderTemplate: failed to render template t.tmpl: tem…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jeremych1000
Comment options

Answer selected by jeremych1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1675 on March 18, 2023 13:08.