configs: Simple test of loading valid configuration files

This test is intended to be an easy-to-maintain catalog of good examples
that we can use to catch certain parsing or decoding regressions easily.

It's not a fully-comprehensive test since it doesn't check the result
of decoding, instead just accepting any decode that completes without
errors. However, an easy-to-maintain test like this is a good complement
to some more specialized tests since we can easily collect good examples
over time and just add them in here.
This commit is contained in:
Martin Atkins 2018-02-02 17:24:28 -08:00
parent e15ec486bf
commit e524d1eb95
15 changed files with 259 additions and 0 deletions

View File

@ -0,0 +1,43 @@
package configs
import (
"io/ioutil"
"path/filepath"
"testing"
)
// TestParseLoadConfigFileSuccess is a simple test that just verifies that
// a number of test configuration files (in test-fixtures/valid-files) can
// be parsed without raising any diagnostics.
//
// This test does not verify that reading these files produces the correct
// file element contents. More detailed assertions may be made on some subset
// of these configuration files in other tests.
func TestParserLoadConfigFileSuccess(t *testing.T) {
files, err := ioutil.ReadDir("test-fixtures/valid-files")
if err != nil {
t.Fatal(err)
}
for _, info := range files {
name := info.Name()
t.Run(name, func(t *testing.T) {
src, err := ioutil.ReadFile(filepath.Join("test-fixtures/valid-files", name))
if err != nil {
t.Fatal(err)
}
parser := testParser(map[string]string{
name: string(src),
})
_, diags := parser.LoadConfigFile(name)
if len(diags) != 0 {
t.Errorf("unexpected diagnostics")
for _, diag := range diags {
t.Logf("- %s", diag)
}
}
})
}
}

View File

@ -0,0 +1,10 @@
terraform {
backend "example" {
foo = "bar"
baz {
bar = "foo"
}
}
}

View File

@ -0,0 +1,15 @@
data "http" "example1" {
}
data "http" "example2" {
url = "http://example.com/"
request_headers = {
"Accept" = "application/json"
}
count = 5
depends_on = [
data.http.example1,
]
}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,16 @@
locals {
# This block intentionally left blank
}
locals {
foo = "foo"
bar = true
}
locals {
baz = "oink"
dunno = "🤷"
rowing = "🚣‍♀️"
π = 3.14159265359
}

View File

@ -0,0 +1,10 @@
{
"locals": {
"foo": "foo",
"bar": true,
"baz": "oink",
"dunno": "🤷",
"rowing": "🚣‍♀️",
"π": 3.14159265359
}
}

View File

@ -0,0 +1,26 @@
module "foo" {
source = "./foo"
# this block intentionally left (almost) blank
}
module "bar" {
source = "hashicorp/bar/aws"
boom = "🎆"
yes = true
}
module "baz" {
source = "git::https://example.com/"
a = 1
count = 12
for_each = ["a", "b", "c"]
depends_on = [
module.bar,
]
}

View File

@ -0,0 +1,25 @@
output "foo" {
value = "hello"
}
output "bar" {
value = local.bar
}
output "baz" {
value = "ssshhhhhhh"
sensitive = true
}
output "cheeze_pizza" {
description = "Nothing special"
value = "🍕"
}
output "π" {
value = 3.14159265359
depends_on = [
pizza.cheese,
]
}

View File

@ -0,0 +1,15 @@
provider "foo" {
}
provider "bar" {
version = ">= 1.0.2"
other = 12
}
provider "bar" {
other = 13
alias = "bar"
}

View File

@ -0,0 +1,7 @@
terraform {
required_providers {
aws = "~> 1.0.0"
consul = "~> 1.2.0"
}
}

View File

@ -0,0 +1,4 @@
terraform {
required_version = "~> 0.12.0"
}

View File

@ -0,0 +1,42 @@
resource "aws_security_group" "firewall" {
lifecycle {
create_before_destroy = true
prevent_destroy = true
ignore_changes = [
description,
]
}
connection {
host = "127.0.0.1"
}
provisioner "local-exec" {
command = "echo hello"
connection {
host = "10.1.2.1"
}
}
provisioner "local-exec" {
command = "echo hello"
}
}
resource "aws_instance" "web" {
ami = "ami-1234"
security_groups = [
"foo",
"bar",
]
network_interface {
device_index = 0
description = "Main network interface"
}
depends_on = [
aws_security_group.firewall,
]
}

View File

@ -0,0 +1,24 @@
variable "foo" {
}
variable "bar" {
default = "hello"
}
variable "baz" {
type = list
}
variable "bar-baz" {
default = []
type = list
}
variable "cheeze_pizza" {
description = "Nothing special"
}
variable "π" {
default = 3.14159265359
}

View File

@ -0,0 +1,21 @@
{
"variable": {
"foo": {},
"bar": {
"default": "hello"
},
"baz": {
"type": "list"
},
"bar-baz": {
"default": [],
"type": "list"
},
"cheese_pizza": {
"description": "Nothing special"
},
"π": {
"default": 3.14159265359
}
}
}