From 1f949100db2952246785d7a45ca2bb96cfb552af Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 26 Oct 2020 11:24:30 -0400 Subject: [PATCH] hclv2 tests: test complex config configuration --- jobspec/parse_test.go | 6 ++ jobspec/test-fixtures/tg-scaling-policy.hcl | 4 + jobspec2/parse_test.go | 17 ++++ .../test-fixtures/config-compatibility.hcl | 78 +++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 jobspec2/test-fixtures/config-compatibility.hcl diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index d2c064f46..bb36383f4 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -1400,6 +1400,12 @@ func TestParse(t *testing.T) { "b": true, "val": 5, "f": .1, + + "check": []map[string]interface{}{ + {"foo": []map[string]interface{}{ + {"query": "some_query"}, + }}, + }, }, Enabled: boolToPtr(false), }, diff --git a/jobspec/test-fixtures/tg-scaling-policy.hcl b/jobspec/test-fixtures/tg-scaling-policy.hcl index 412406b62..ae157ae65 100644 --- a/jobspec/test-fixtures/tg-scaling-policy.hcl +++ b/jobspec/test-fixtures/tg-scaling-policy.hcl @@ -10,6 +10,10 @@ job "elastic" { b = true val = 5 f = 0.1 + + check "foo" { + query = "some_query" + } } } } diff --git a/jobspec2/parse_test.go b/jobspec2/parse_test.go index 9d6a20b47..875f3f634 100644 --- a/jobspec2/parse_test.go +++ b/jobspec2/parse_test.go @@ -38,6 +38,23 @@ func TestEquivalentToHCL1(t *testing.T) { } } +func TestEquivalentToHCL1_ComplexConfig(t *testing.T) { + name := "./test-fixtures/config-compatibility.hcl" + f, err := os.Open(name) + require.NoError(t, err) + defer f.Close() + + job1, err := jobspec.Parse(f) + require.NoError(t, err) + + f.Seek(0, 0) + + job2, err := Parse(name, f) + require.NoError(t, err) + + require.Equal(t, job1, job2) +} + func TestParse_VarsAndFunctions(t *testing.T) { hcl := ` job "example" { diff --git a/jobspec2/test-fixtures/config-compatibility.hcl b/jobspec2/test-fixtures/config-compatibility.hcl new file mode 100644 index 000000000..c082b718b --- /dev/null +++ b/jobspec2/test-fixtures/config-compatibility.hcl @@ -0,0 +1,78 @@ +job "example" { + group "group" { + task "task" { + config { + ## arbitrary structures to compare HCLv1 and HCLv2 + ## HCLv2 must parse the same way HCLv1 parser does + + + # primitive attrs + attr_string = "b" + attr_int = 3 + attr_large_int = 21474836470 + attr_float = 3.2 + + # lists attrs + attr_list_string = ["a", "b"] + attr_list_int = [1, 2, 4] + attr_list_float = [1.2, 2.3, 4.2] + attr_list_hetro = [1, "a", 3.4, { "k" = "v" }] + attr_list_empty = [] + + # map attrs + attr_map = { "KEY" = "VAL", "KEY2" = "VAL2" } + attr_map_empty = {} + + # simple blocks + block1 { + k = "b" + key2 = "v2" + } + labeled_block "label1" { + k = "b" + } + multi_labeled_block "label1" "label2" "label3" { + k = "b" + } + + # repeated block + repeated_block_type { + a = 2 + } + repeated_block_type { + b = 3 + } + + # repeated blocks with labels + label_repeated "l1" { + a = 1 + } + label_repeated "l1" { + a = 2 + } + label_repeated "l2" "l21" { + a = 3 + } + label_repeated "l2" "l21" "l23" { + a = 4 + } + label_repeated "l3" { + a = 5 + } + + # nested blocks + outer_block "l1" { + level = 1 + inner_block "l2" { + level = 2 + most_inner "l3" { + level = 3 + + inner_map = { "K" = "V" } + } + } + } + } + } + } +}