Skip to content

Commit

Permalink
Use a single client in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mongey committed Jun 3, 2018
1 parent 0ce2aca commit 3127f8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
30 changes: 19 additions & 11 deletions kafka/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package kafka

import (
"log"
"os"
"strings"
"testing"

"github.com/hashicorp/terraform/config"
Expand All @@ -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,
}
Expand Down
13 changes: 4 additions & 9 deletions kafka/resource_kafka_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 3127f8e

Please sign in to comment.