<commit_before>package aws

import (
	"fmt"
	"os"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/directconnect"
	"github.com/hashicorp/terraform/helper/acctest"
	"github.com/hashicorp/terraform/helper/resource"
	"github.com/hashicorp/terraform/terraform"
)

func TestAccAwsDxPublicVirtualInterface_basic(t *testing.T) {
	key := "DX_CONNECTION_ID"
	connectionId := os.Getenv(key)
	if connectionId == "" {
		t.Skipf("Environment variable %s is not set", key)
	}
	vifName := fmt.Sprintf("tf-dx-vif-%s", acctest.RandString(5))

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAwsDxPublicVirtualInterfaceDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccDxPublicVirtualInterfaceConfig_noTags(connectionId, vifName),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAwsDxPublicVirtualInterfaceExists("aws_dx_public_virtual_interface.foo"),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "name", vifName),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "tags.%", "0"),
				),
			},
			{
				Config: testAccDxPublicVirtualInterfaceConfig_tags(connectionId, vifName),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAwsDxPublicVirtualInterfaceExists("aws_dx_public_virtual_interface.foo"),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "name", vifName),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "tags.%", "1"),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "tags.Environment", "test"),
				),
			},
			// Test import.
			{
				ResourceName:      "aws_dx_public_virtual_interface.foo",
				ImportState:       true,
				ImportStateVerify: true,
			},
		},
	})
}

func testAccCheckAwsDxPublicVirtualInterfaceDestroy(s *terraform.State) error {
	conn := testAccProvider.Meta().(*AWSClient).dxconn

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "aws_dx_public_virtual_interface" {
			continue
		}

		input := &directconnect.DescribeVirtualInterfacesInput{
			VirtualInterfaceId: aws.String(rs.Primary.ID),
		}

		resp, err := conn.DescribeVirtualInterfaces(input)
		if err != nil {
			return err
		}
		for _, v := range resp.VirtualInterfaces {
			if *v.VirtualInterfaceId == rs.Primary.ID && !(*v.VirtualInterfaceState == directconnect.VirtualInterfaceStateDeleted) {
				return fmt.Errorf("[DESTROY ERROR] Dx Public VIF (%s) not deleted", rs.Primary.ID)
			}
		}
	}
	return nil
}

func testAccCheckAwsDxPublicVirtualInterfaceExists(name string) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		_, ok := s.RootModule().Resources[name]
		if !ok {
			return fmt.Errorf("Not found: %s", name)
		}

		return nil
	}
}

func testAccDxPublicVirtualInterfaceConfig_noTags(cid, n string) string {
	return fmt.Sprintf(`
resource "aws_dx_public_virtual_interface" "foo" {
  connection_id    = "%s"

  name           = "%s"
  vlan           = 4094
  address_family = "ipv4"
  bgp_asn        = 65352

  customer_address = "172.16.31.10/30"
  amazon_address   = "175.45.176.2/30"
  route_filter_prefixes = [
    "172.16.58.3/24",
	"192.168.127.12/22"
  ]
}
    `, cid, n)
}

func testAccDxPublicVirtualInterfaceConfig_tags(cid, n string) string {
	return fmt.Sprintf(`
resource "aws_dx_public_virtual_interface" "foo" {
  connection_id    = "%s"

  name           = "%s"
  vlan           = 4094
  address_family = "ipv4"
  bgp_asn        = 65352

  customer_address = "172.16.31.10/30"
  amazon_address   = "172.16.17.32/30"
  route_filter_prefixes = [
    "172.16.58.3/24",
	"192.168.127.12/22"
  ]

  tags {
    Environment = "test"
  }
}
    `, cid, n)
}
<commit_msg>Fix indentation for configuration generation.<commit_after>package aws

import (
	"fmt"
	"os"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/directconnect"
	"github.com/hashicorp/terraform/helper/acctest"
	"github.com/hashicorp/terraform/helper/resource"
	"github.com/hashicorp/terraform/terraform"
)

func TestAccAwsDxPublicVirtualInterface_basic(t *testing.T) {
	key := "DX_CONNECTION_ID"
	connectionId := os.Getenv(key)
	if connectionId == "" {
		t.Skipf("Environment variable %s is not set", key)
	}
	vifName := fmt.Sprintf("tf-dx-vif-%s", acctest.RandString(5))

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAwsDxPublicVirtualInterfaceDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccDxPublicVirtualInterfaceConfig_noTags(connectionId, vifName),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAwsDxPublicVirtualInterfaceExists("aws_dx_public_virtual_interface.foo"),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "name", vifName),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "tags.%", "0"),
				),
			},
			{
				Config: testAccDxPublicVirtualInterfaceConfig_tags(connectionId, vifName),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAwsDxPublicVirtualInterfaceExists("aws_dx_public_virtual_interface.foo"),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "name", vifName),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "tags.%", "1"),
					resource.TestCheckResourceAttr("aws_dx_public_virtual_interface.foo", "tags.Environment", "test"),
				),
			},
			// Test import.
			{
				ResourceName:      "aws_dx_public_virtual_interface.foo",
				ImportState:       true,
				ImportStateVerify: true,
			},
		},
	})
}

func testAccCheckAwsDxPublicVirtualInterfaceDestroy(s *terraform.State) error {
	conn := testAccProvider.Meta().(*AWSClient).dxconn

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "aws_dx_public_virtual_interface" {
			continue
		}

		input := &directconnect.DescribeVirtualInterfacesInput{
			VirtualInterfaceId: aws.String(rs.Primary.ID),
		}

		resp, err := conn.DescribeVirtualInterfaces(input)
		if err != nil {
			return err
		}
		for _, v := range resp.VirtualInterfaces {
			if *v.VirtualInterfaceId == rs.Primary.ID && !(*v.VirtualInterfaceState == directconnect.VirtualInterfaceStateDeleted) {
				return fmt.Errorf("[DESTROY ERROR] Dx Public VIF (%s) not deleted", rs.Primary.ID)
			}
		}
	}
	return nil
}

func testAccCheckAwsDxPublicVirtualInterfaceExists(name string) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		_, ok := s.RootModule().Resources[name]
		if !ok {
			return fmt.Errorf("Not found: %s", name)
		}

		return nil
	}
}

func testAccDxPublicVirtualInterfaceConfig_noTags(cid, n string) string {
	return fmt.Sprintf(`
resource "aws_dx_public_virtual_interface" "foo" {
  connection_id    = "%s"

  name           = "%s"
  vlan           = 4094
  address_family = "ipv4"
  bgp_asn        = 65352

  customer_address = "172.16.31.10/30"
  amazon_address   = "172.16.17.32/30"
  route_filter_prefixes = [
    "172.16.58.3/24",
	"192.168.127.12/22"
  ]
}
`, cid, n)
}

func testAccDxPublicVirtualInterfaceConfig_tags(cid, n string) string {
	return fmt.Sprintf(`
resource "aws_dx_public_virtual_interface" "foo" {
  connection_id    = "%s"

  name           = "%s"
  vlan           = 4094
  address_family = "ipv4"
  bgp_asn        = 65352

  customer_address = "172.16.31.10/30"
  amazon_address   = "172.16.17.32/30"
  route_filter_prefixes = [
    "172.16.58.3/24",
	"192.168.127.12/22"
  ]

  tags {
    Environment = "test"
  }
}
`, cid, n)
}

{'fraction_non_alphanumeric': 0.1278580814717477, 'fraction_numerical': 0.029697766097240473, 'mean_word_length': 4.094377510040161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 16, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1365754', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2671, 'n_words': 410}