From 742edb5215b6d7b7e2d31b16043b56e72b709399 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 17 May 2023 14:05:06 +0200 Subject: [PATCH] added unknown type test --- libs/template/schema_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libs/template/schema_test.go b/libs/template/schema_test.go index 962262b1a..cbb007ac6 100644 --- a/libs/template/schema_test.go +++ b/libs/template/schema_test.go @@ -66,3 +66,26 @@ func TestTemplateSchemaCastFloatToInt(t *testing.T) { assert.IsType(t, true, config["bool_val"]) assert.IsType(t, "abc", config["string_val"]) } + +func TestTemplateSchemaCastFloatToIntFailsForUnknownTypes(t *testing.T) { + // define schema for config + schemaJson := `{ + "foo": { + "type": "integer" + } + }` + var schema Schema + err := json.Unmarshal([]byte(schemaJson), &schema) + require.NoError(t, err) + + // define the config + configJson := `{ + "bar": true + }` + var config map[string]any + err = json.Unmarshal([]byte(configJson), &config) + require.NoError(t, err) + + err = schema.CastFloatToInt(config) + assert.ErrorContains(t, err, "bar is not defined as an input parameter for the template") +}