forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCL identifiers may need to be quoted, so always quote them to be safe.
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package command | ||
|
||
import "testing" | ||
|
||
// The command package has it's own HCL encoder to encode variables to push. | ||
// Make sure the variable we encode parse correctly | ||
func TestHCLEncoder_parse(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
Val interface{} | ||
Error bool | ||
}{ | ||
{ | ||
Name: "int", | ||
Val: 12345, | ||
}, | ||
{ | ||
Name: "float", | ||
Val: 1.2345, | ||
}, | ||
{ | ||
Name: "string", | ||
Val: "terraform", | ||
}, | ||
{ | ||
Name: "list", | ||
Val: []interface{}{"a", "b", "c"}, | ||
}, | ||
{ | ||
Name: "map", | ||
Val: map[string]interface{}{ | ||
"a": 1, | ||
}, | ||
}, | ||
// a numeric looking identifier requires quotes | ||
{ | ||
Name: "map_with_quoted_key", | ||
Val: map[string]interface{}{ | ||
"0.0.0.0/24": "mask", | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.Name, func(t *testing.T) { | ||
_, err := encodeHCL(c.Val) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
} | ||
} |