github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/consul/data_source_consul_agent_self_test.go (about) 1 package consul 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccDataConsulAgentSelf_basic(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 Steps: []resource.TestStep{ 16 resource.TestStep{ 17 Config: testAccDataConsulAgentSelfConfig, 18 Check: resource.ComposeTestCheckFunc( 19 testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_datacenter", "<all>"), 20 testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_default_policy", "<all>"), 21 testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_disabled_ttl", "<all>"), 22 testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_down_policy", "<all>"), 23 testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_enforce_0_8_semantics", "<all>"), 24 testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_ttl", "<all>"), 25 testAccCheckDataSourceValue("data.consul_agent_self.read", "advertise_addr", "<any>"), 26 testAccCheckDataSourceValue("data.consul_agent_self.read", "bind_addr", "<any>"), 27 testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_expect", "<all>"), 28 testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_mode", "false"), 29 testAccCheckDataSourceValue("data.consul_agent_self.read", "client_addr", "<any>"), 30 testAccCheckDataSourceValue("data.consul_agent_self.read", "datacenter", "<any>"), 31 testAccCheckDataSourceValue("data.consul_agent_self.read", "dev_mode", "<any>"), 32 testAccCheckDataSourceValue("data.consul_agent_self.read", "domain", "<any>"), 33 testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_anonymous_signature", "<any>"), 34 testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_coordinates", "<any>"), 35 testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_debug", "<any>"), 36 testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_remote_exec", "<any>"), 37 testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_syslog", "<any>"), 38 testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_ui", "<any>"), 39 testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_update_check", "<any>"), 40 testAccCheckDataSourceValue("data.consul_agent_self.read", "id", "<any>"), 41 testAccCheckDataSourceValue("data.consul_agent_self.read", "leave_on_int", "<any>"), 42 testAccCheckDataSourceValue("data.consul_agent_self.read", "leave_on_term", "<any>"), 43 testAccCheckDataSourceValue("data.consul_agent_self.read", "log_level", "<any>"), 44 testAccCheckDataSourceValue("data.consul_agent_self.read", "name", "<any>"), 45 testAccCheckDataSourceValue("data.consul_agent_self.read", "pid_file", "<all>"), 46 testAccCheckDataSourceValue("data.consul_agent_self.read", "rejoin_after_leave", "<any>"), 47 // testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_join", "<all>"), 48 // testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_join_wan", "<any>"), 49 testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_max_attempts", "<any>"), 50 testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_max_attempts_wan", "<any>"), 51 testAccCheckDataSourceValue("data.consul_agent_self.read", "serf_lan_bind_addr", "<all>"), 52 testAccCheckDataSourceValue("data.consul_agent_self.read", "serf_wan_bind_addr", "<all>"), 53 testAccCheckDataSourceValue("data.consul_agent_self.read", "server_mode", "<any>"), 54 testAccCheckDataSourceValue("data.consul_agent_self.read", "server_name", "<all>"), 55 // testAccCheckDataSourceValue("data.consul_agent_self.read", "start_join", "<all>"), 56 // testAccCheckDataSourceValue("data.consul_agent_self.read", "start_join_wan", "<all>"), 57 testAccCheckDataSourceValue("data.consul_agent_self.read", "syslog_facility", "<any>"), 58 testAccCheckDataSourceValue("data.consul_agent_self.read", "telemetry.enable_hostname", "<all>"), 59 testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_ca_file", "<all>"), 60 testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_cert_file", "<all>"), 61 testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_key_file", "<all>"), 62 testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_verify_incoming", "<any>"), 63 testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_verify_outgoing", "<any>"), 64 testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_verify_server_hostname", "<any>"), 65 ), 66 }, 67 }, 68 }) 69 } 70 71 func testAccCheckDataSourceValue(n, attr, val string) resource.TestCheckFunc { 72 return func(s *terraform.State) error { 73 rn, ok := s.RootModule().Resources[n] 74 if !ok { 75 return fmt.Errorf("Resource not found") 76 } 77 out, found := rn.Primary.Attributes[attr] 78 switch { 79 case !found: 80 return fmt.Errorf("Attribute '%s' not found: %#v", attr, rn.Primary.Attributes) 81 case val == "<all>": 82 // Value found, don't care what the payload is (including the zero value) 83 case val != "<any>" && out != val: 84 return fmt.Errorf("Attribute '%s' value '%s' != '%s'", attr, out, val) 85 case val == "<any>" && out == "": 86 return fmt.Errorf("Attribute '%s' value '%s'", attr, out) 87 } 88 return nil 89 } 90 } 91 92 const testAccDataConsulAgentSelfConfig = ` 93 data "consul_agent_self" "read" { 94 } 95 `