From 3127f8ea6e00a7b28e4768326d309462548ec9a8 Mon Sep 17 00:00:00 2001 From: Conor Mongey Date: Sun, 3 Jun 2018 02:25:42 +0100 Subject: [PATCH] Use a single client in tests --- kafka/provider_test.go | 30 +++++++++++++++++++----------- kafka/resource_kafka_topic_test.go | 13 ++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/kafka/provider_test.go b/kafka/provider_test.go index 2d601822..55c53498 100644 --- a/kafka/provider_test.go +++ b/kafka/provider_test.go @@ -1,6 +1,9 @@ package kafka import ( + "log" + "os" + "strings" "testing" "github.com/hashicorp/terraform/config" @@ -18,25 +21,30 @@ func TestProvider(t *testing.T) { } func testAccPreCheck(t *testing.T) { + client := testProvider.Meta().(*Client) + if client == nil { + t.Fatal("No client") + } } func accProvider() map[string]terraform.ResourceProvider { + log.Println("[INFO] Setting up override for a provider") provider := Provider().(*schema.Provider) - bootstrap_servers := []string{"localhost:9092"} - raw := map[string]interface{}{ - "bootstrap_servers": bootstrap_servers, - } + bs := strings.Split(os.Getenv("KAFKA_BOOTSTRAP_SERVER"), ",") + bootstrapServers := []string{} - rawConfig, err := config.NewRawConfig(raw) - if err != nil { - panic(err) + for _, v := range bs { + if v != "" { + bootstrapServers = append(bootstrapServers, v) + } } - - err = provider.Configure(terraform.NewResourceConfig(rawConfig)) - if err != nil { - panic(err) + raw := map[string]interface{}{ + "bootstrap_servers": bootstrapServers, } + rawConfig, _ := config.NewRawConfig(raw) + _ = provider.Configure(terraform.NewResourceConfig(rawConfig)) + testProvider = provider return map[string]terraform.ResourceProvider{ "kafka": provider, } diff --git a/kafka/resource_kafka_topic_test.go b/kafka/resource_kafka_topic_test.go index 9b9dcf26..ea4ee843 100644 --- a/kafka/resource_kafka_topic_test.go +++ b/kafka/resource_kafka_topic_test.go @@ -63,9 +63,7 @@ func testResourceTopic_initialCheck(s *terraform.State) error { return fmt.Errorf("unexpected topic name %s", name) } - client, _ := NewClient(&Config{ - BootstrapServers: &[]string{"localhost:9092"}, - }) + client := testProvider.Meta().(*Client) topic, err := client.ReadTopic("syslog") @@ -84,9 +82,8 @@ func testResourceTopic_initialCheck(s *terraform.State) error { } func testResourceTopic_updateCheck(s *terraform.State) error { - client, _ := NewClient(&Config{ - BootstrapServers: &[]string{"localhost:9092"}, - }) + client := testProvider.Meta().(*Client) + topic, err := client.ReadTopic("syslog") if err != nil { return err @@ -107,9 +104,7 @@ func testResourceTopic_updateCheck(s *terraform.State) error { } func testResourceTopic_updatePartitionsCheck(s *terraform.State) error { - client, _ := NewClient(&Config{ - BootstrapServers: &[]string{"localhost:9092"}, - }) + client := testProvider.Meta().(*Client) topic, err := client.ReadTopic("syslog") if err != nil {