hclv2 tests: test complex config configuration

This commit is contained in:
Mahmood Ali
2020-10-26 11:24:30 -04:00
parent f6d921f157
commit 1f949100db
4 changed files with 105 additions and 0 deletions

View File

@@ -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),
},

View File

@@ -10,6 +10,10 @@ job "elastic" {
b = true
val = 5
f = 0.1
check "foo" {
query = "some_query"
}
}
}
}

View File

@@ -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" {

View File

@@ -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" }
}
}
}
}
}
}
}