tmp_dir = input("tmp_dir")
resource_dir = input("resource_dir")

control "inspec terraform generate --name AWS-terraform-two-tier" do

  describe directory tmp_dir do
    it { should exist }
  end

  describe directory resource_dir do
    it { should exist }
  end

  describe command("bundle exec inspec terraform generate --name #{tmp_dir}/AWS-terraform-two-tier -t test/fixtures/terraform/tfstates/aws-terraform-two-tier-example.tfstate --platform aws --resourcepath #{resource_dir} --title AWS-TERRAFORM-TWO-TIER --maintainer 'Matt Ray' --copyright nobody --email inspec-iggy@mattray.dev --summary 'AWS-terraform-two-tier testing profile' --version 1.2.3") do
    its("exit_status") { should cmp 0 }
    its("stdout") { should match(/InSpec Iggy Code Generator/) } # skip the non ASCII characters
    its("stdout") { should match(/Creating new profile at/) }
    its("stdout") { should match(/Creating file/) }
    its("stdout") { should match(/Creating directory/) }
  end

  describe directory "#{tmp_dir}/AWS-terraform-two-tier/" do
    it { should exist }
  end

  describe directory "#{tmp_dir}/AWS-terraform-two-tier/controls/" do
    it { should exist }
  end

  describe file "#{tmp_dir}/AWS-terraform-two-tier/inspec.yml" do
    its("content") { should match(/AWS-terraform-two-tier"$/) }
    its("content") { should match(/title: AWS-TERRAFORM-TWO-TIER$/) }
    its("content") { should match(/maintainer: Matt Ray$/) }
    its("content") { should match(/copyright: nobody$/) }
    its("content") { should match(/copyright_email: inspec-iggy@mattray.dev$/) }
    its("content") { should match(/license: Apache-2.0$/) }
    its("content") { should match(/summary: AWS-terraform-two-tier testing profile$/) }
    its("content") { should match(/version: 1.2.3$/) }
    its("content") { should match(%r{description: Generated by InSpec-Iggy v0.8.1 from the test/fixtures/terraform/tfstates/aws-terraform-two-tier-example.tfstate$}) }
    its("content") { should match(/inspec_version: "~> 4"$/) }
    its("content") { should match(/depends:$/) }
    its("content") { should match(/- name: inspec-aws$/) }
    its("content") { should match(%r{url: https://github.com/inspec/inspec-aws/archive/master.tar.gz$}) }
    its("content") { should match(/supports:$/) }
    its("content") { should match(/- platform: aws$/) }
  end

  describe file "#{tmp_dir}/AWS-terraform-two-tier/README.md" do
    its("content") { should match(/#*AWS-terraform-two-tier$/) }
    its("content") { should match(%r{^This profile was generated by InSpec-Iggy v0.8.1 from the test/fixtures/terraform/tfstates/aws-terraform-two-tier-example.tfstate source file.$}) }
  end

  describe file "#{tmp_dir}/AWS-terraform-two-tier/controls/generated.rb" do
    its("content") { should match(/aws_ec2_instance::i-05c6d20469a0a0ee9 from the source file/) }
    its("content") { should match(/aws_security_group::sg-01199abc1619d7613 from the source file/) }
    its("content") { should match(/aws_security_group::sg-0eac4a147658285b7 from the source file/) }
    its("content") { should match(/aws_subnet::subnet-00f265d40d3d0a227 from the source file/) }
    its("content") { should match(/aws_vpc::vpc-035d7e339ce59ad62 from the source file/) }
    its("content") { should match(%r{test/fixtures/terraform/tfstates/aws-terraform-two-tier-example.tfstate$}) }
    its("content") { should match(/control "aws_ec2_instance::i-05c6d20469a0a0ee9" do$/) }
    its("content") { should match(/control "aws_elb::terraform-example-elb" do$/) }
    its("content") { should match(/control "aws_security_group::sg-01199abc1619d7613" do$/) }
    its("content") { should match(/control "aws_security_group::sg-0eac4a147658285b7" do$/) }
    its("content") { should match(/control "aws_subnet::subnet-00f265d40d3d0a227" do$/) }
    its("content") { should match(/control "aws_vpc::vpc-035d7e339ce59ad62" do$/) }
    its("content") { should match(/describe aws_ec2_instance\({:instance_id=>"i-05c6d20469a0a0ee9"}\) do$/) }
    its("content") { should match(/describe aws_elb\({:load_balancer_name=>"terraform-example-elb"}\) do$/) }
    its("content") { should match(/describe aws_security_group\({:group_id=>"sg-01199abc1619d7613", :vpc_id=>"vpc-035d7e339ce59ad62"}\) do$/) }
    its("content") { should match(/describe aws_security_group\({:group_id=>"sg-0eac4a147658285b7", :vpc_id=>"vpc-035d7e339ce59ad62"}\) do$/) }
    its("content") { should match(/describe aws_subnet\({:subnet_id=>"subnet-00f265d40d3d0a227"}\) do$/) }
    its("content") { should match(/describe aws_vpc\({:vpc_id=>"vpc-035d7e339ce59ad62"}\) do$/) }
    its("content") { should match(/it { should exist }$/) }
    its("content") { should match(/its\("availability_zone"\) { should cmp "us-west-2c" }$/) }
    its("content") { should match(/its\("availability_zones"\) { should cmp \["us-west-2c"\] }$/) }
    its("content") { should match(%r{its\("cidr_block"\) { should cmp "10.0.0.0/16" }$}) }
    its("content") { should match(%r{its\("cidr_block"\) { should cmp "10.0.1.0/24" }$}) }
    its("content") { should match(/its\("description"\) { should cmp "Used in the terraform" }$/) }
    its("content") { should match(/its\("dhcp_options_id"\) { should cmp "dopt-8d3211eb" }$/) }
    its("content") { should match(/its\("dns_name"\) { should cmp "terraform-example-elb-2051343015.us-west-2.elb.amazonaws.com" }$/) }
    its("content") { should match(/its\("group_name"\) { should cmp "terraform_example" }$/) }
    its("content") { should match(/its\("group_name"\) { should cmp "terraform_example_elb" }$/) }
    its("content") { should match(/its\("instance_tenancy"\) { should cmp "default" }$/) }
    its("content") { should match(/its\("load_balancer_name"\) { should cmp "terraform-example-elb" }$/) }
    its("content") { should match(/its\("owner_id"\) { should cmp "112758395563" }$/) }
    its("content") { should match(/its\("subnet_id"\) { should cmp "subnet-00f265d40d3d0a227" }$/) }
    its("content") { should match(/its\("subnets"\) { should cmp \["subnet-00f265d40d3d0a227"\] }$/) }
    its("content") { should match(/its\("vpc_id"\) { should cmp "vpc-035d7e339ce59ad62" }$/) }
    its("content") { should match(/title "AWS-TERRAFORM-TWO-TIER: generated by Iggy v0.8.1"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_ec2_instance::i-05c6d20469a0a0ee9"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_elb::terraform-example-elb"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_security_group::sg-01199abc1619d7613"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_security_group::sg-0eac4a147658285b7"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_subnet::subnet-00f265d40d3d0a227"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_vpc::vpc-035d7e339ce59ad62"$/) }
  end

  describe command("bundle exec inspec terraform generate --name #{tmp_dir}/AWS-terraform-elb-example -t test/fixtures/terraform/tfstates/aws-terraform-elb-example.tfstate --platform aws --resourcepath #{resource_dir} --title AWS-TERRAFORM-ELB-EXAMPLE --maintainer 'Matt Ray' --copyright nobody --email inspec-iggy@mattray.dev --summary 'AWS-terraform-elb-example testing profile' --version 1.2.3") do
    its("exit_status") { should cmp 0 }
    its("stdout") { should match(/InSpec Iggy Code Generator/) } # skip the non ASCII characters
    its("stdout") { should match(/Creating new profile at/) }
    its("stdout") { should match(/Creating file/) }
    its("stdout") { should match(/Creating directory/) }
  end

  describe directory "#{tmp_dir}/AWS-terraform-elb-example/" do
    it { should exist }
  end

  describe directory "#{tmp_dir}/AWS-terraform-elb-example/controls/" do
    it { should exist }
  end

  describe file "#{tmp_dir}/AWS-terraform-elb-example/inspec.yml" do
    its("content") { should match(/AWS-terraform-elb-example"$/) }
    its("content") { should match(/title: AWS-TERRAFORM-ELB-EXAMPLE$/) }
    its("content") { should match(/maintainer: Matt Ray$/) }
    its("content") { should match(/copyright: nobody$/) }
    its("content") { should match(/copyright_email: inspec-iggy@mattray.dev$/) }
    its("content") { should match(/license: Apache-2.0$/) }
    its("content") { should match(/summary: AWS-terraform-elb-example testing profile$/) }
    its("content") { should match(/version: 1.2.3$/) }
    its("content") { should match(%r{description: Generated by InSpec-Iggy v0.8.1 from the test/fixtures/terraform/tfstates/aws-terraform-elb-example.tfstate$}) }
    its("content") { should match(/inspec_version: "~> 4"$/) }
    its("content") { should match(/depends:$/) }
    its("content") { should match(/- name: inspec-aws$/) }
    its("content") { should match(%r{url: https://github.com/inspec/inspec-aws/archive/master.tar.gz$}) }
    its("content") { should match(/supports:$/) }
    its("content") { should match(/- platform: aws$/) }
  end

  describe file "#{tmp_dir}/AWS-terraform-elb-example/README.md" do
    its("content") { should match(/#*AWS-terraform-elb-example$/) }
    its("content") { should match(%r{^This profile was generated by InSpec-Iggy v0.8.1 from the test/fixtures/terraform/tfstates/aws-terraform-elb-example.tfstate source file.$}) }
  end

  describe file "#{tmp_dir}/AWS-terraform-elb-example/controls/generated.rb" do
    its("content") { should match(/Generated by InSpec-Iggy v0.8.1$/) }
    its("content") { should match(%r{/test/fixtures/terraform/tfstates/aws-terraform-elb-example.tfstate$}) }
    its("content") { should match(/aws_ec2_instance::i-0093ad1c115857458 from the source file/) }
    its("content") { should match(/aws_elb::example-elb from the source file/) }
    its("content") { should match(/aws_route_table::rtb-0beaa5171b8c1a961 from the source file/) }
    its("content") { should match(/aws_security_group::sg-071f16066bbf117eb from the source file/) }
    its("content") { should match(/aws_security_group::sg-076d9eeaf5f60b04e from the source file/) }
    its("content") { should match(/aws_subnet::subnet-00c91dee0349a24ea from the source file/) }
    its("content") { should match(/aws_vpc::vpc-09b99a40b26aa93a1 from the source file/) }
    its("content") { should match(/control "aws_ec2_instance::i-0093ad1c115857458" do$/) }
    its("content") { should match(/control "aws_elb::example-elb" do$/) }
    its("content") { should match(/control "aws_route_table::rtb-0beaa5171b8c1a961" do$/) }
    its("content") { should match(/control "aws_security_group::sg-071f16066bbf117eb" do$/) }
    its("content") { should match(/control "aws_security_group::sg-076d9eeaf5f60b04e" do$/) }
    its("content") { should match(/control "aws_subnet::subnet-00c91dee0349a24ea" do$/) }
    its("content") { should match(/control "aws_vpc::vpc-09b99a40b26aa93a1" do$/) }
    its("content") { should match(/describe aws_ec2_instance\({:instance_id=>"i-0093ad1c115857458"}\) do$/) }
    its("content") { should match(/describe aws_elb\({:load_balancer_name=>"example-elb"}\) do$/) }
    its("content") { should match(/describe aws_route_table\({:route_table_id=>"rtb-0beaa5171b8c1a961"}\) do$/) }
    its("content") { should match(/describe aws_security_group\({:group_id=>"sg-071f16066bbf117eb", :vpc_id=>"vpc-09b99a40b26aa93a1"}\) do$/) }
    its("content") { should match(/describe aws_security_group\({:group_id=>"sg-076d9eeaf5f60b04e", :vpc_id=>"vpc-09b99a40b26aa93a1"}\) do$/) }
    its("content") { should match(/describe aws_subnet\({:subnet_id=>"subnet-00c91dee0349a24ea"}\) do$/) }
    its("content") { should match(/describe aws_vpc\({:vpc_id=>"vpc-09b99a40b26aa93a1"}\) do$/) }
    its("content") { should match(/impact 1.0$/) }
    its("content") { should match(/it { should exist }$/) }
    its("content") { should match(/its\("availability_zone"\) { should cmp "us-west-2c" }$/) }
    its("content") { should match(/its\("availability_zones"\) { should cmp \["us-west-2c"\] }$/) }
    its("content") { should match(%r{its\("cidr_block"\) { should cmp "10.0.0.0/16" }$}) }
    its("content") { should match(%r{its\("cidr_block"\) { should cmp "10.0.0.0/24" }$}) }
    its("content") { should match(/its\("description"\) { should cmp "Used in the terraform" }$/) }
    its("content") { should match(/its\("dhcp_options_id"\) { should cmp "dopt-8d3211eb" }$/) }
    its("content") { should match(/its\("dns_name"\) { should cmp "example-elb-99716389.us-west-2.elb.amazonaws.com" }$/) }
    its("content") { should match(/its\("group_name"\) { should cmp "elb_sg" }$/) }
    its("content") { should match(/its\("group_name"\) { should cmp "instance_sg" }$/) }
    its("content") { should match(/its\("instance_tenancy"\) { should cmp "default" }$/) }
    its("content") { should match(/its\("load_balancer_name"\) { should cmp "example-elb" }$/) }
    its("content") { should match(/its\("owner_id"\) { should cmp "112758395563" }$/) }
    its("content") { should match(/its\("propagating_vgws"\) { should cmp \[\] }$/) }
    its("content") { should match(/its\("subnet_id"\) { should cmp "subnet-00c91dee0349a24ea" }$/) }
    its("content") { should match(/its\("subnets"\) { should cmp \["subnet-00c91dee0349a24ea"\] }$/) }
    its("content") { should match(/its\("vpc_id"\) { should cmp "vpc-09b99a40b26aa93a1" }$/) }
    its("content") { should match(/title "AWS-TERRAFORM-ELB-EXAMPLE: generated by Iggy v0.8.1"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_ec2_instance::i-0093ad1c115857458"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_elb::example-elb"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_route_table::rtb-0beaa5171b8c1a961"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_security_group::sg-071f16066bbf117eb"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_security_group::sg-076d9eeaf5f60b04e"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_subnet::subnet-00c91dee0349a24ea"$/) }
    its("content") { should match(/title "InSpec-Iggy aws_vpc::vpc-09b99a40b26aa93a1"$/) }
  end

end
