2015-10-16 20:22:28 +00:00
|
|
|
package printer
|
2015-10-03 00:30:57 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2015-10-24 21:04:31 +00:00
|
|
|
"github.com/fatih/hcl/parser"
|
2015-10-03 00:30:57 +00:00
|
|
|
)
|
|
|
|
|
2015-10-24 22:23:50 +00:00
|
|
|
var listHCL = `foo = ["fatih", "arslan"]`
|
|
|
|
var listHCL2 = `foo = [
|
|
|
|
"fatih",
|
|
|
|
"arslan",
|
|
|
|
]`
|
|
|
|
|
2015-10-03 00:30:57 +00:00
|
|
|
var complexHcl = `// This comes from Terraform, as a test
|
|
|
|
variable "foo" {
|
|
|
|
default = "bar"
|
|
|
|
description = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "aws" {
|
|
|
|
access_key = "foo"
|
|
|
|
secret_key = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "do" {
|
|
|
|
api_key = "${var.foo}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "firewall" {
|
|
|
|
count = 5
|
|
|
|
}
|
|
|
|
|
|
|
|
resource aws_instance "web" {
|
|
|
|
ami = "${var.foo}"
|
|
|
|
security_groups = [
|
|
|
|
"foo",
|
|
|
|
"${aws_security_group.firewall.foo}"
|
|
|
|
]
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
device_index = 0
|
|
|
|
description = "Main network interface"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_instance" "db" {
|
|
|
|
security_groups = "${aws_security_group.firewall.*.id}"
|
|
|
|
VPC = "foo"
|
|
|
|
|
|
|
|
depends_on = ["aws_instance.web"]
|
|
|
|
}
|
|
|
|
|
|
|
|
output "web_ip" {
|
|
|
|
value = "${aws_instance.web.private_ip}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
func TestPrint(t *testing.T) {
|
2015-10-24 22:23:50 +00:00
|
|
|
// node, err := parser.Parse([]byte(complexHcl))
|
|
|
|
node, err := parser.Parse([]byte(listHCL2))
|
2015-10-03 00:30:57 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-10-24 21:04:31 +00:00
|
|
|
if err := Fprint(os.Stdout, node); err != nil {
|
2015-10-03 00:30:57 +00:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|