opentofu/builtin/providers/consul/resource_provider_test.go
Paul Hinze 069425a700 consul: Fix several problems w/ consul_keys update
Implementation notes:

 * The hash implementation was not considering key value, causing "diffs
   did not match" errors when a value was updated. Switching to default
   HashResource implementation fixes this
 * Using HashResource as a default exposed a bug in helper/schema that
   needed to be fixed so the Set function is picked up properly during
   Read
 * Stop writing back values into the `key` attribute; it triggers extra
   diffs when `default` is used. Computed values all just go into `var`.
 * Includes a state migration to prevent unnecessary diffs based on
   "key" attribute hashcodes changing.

In the tests:

 * Switch from leaning on the public demo Consul instance to requiring a
   CONSUL_HTTP_ADDR variable be set pointing to a `consul agent -dev`
   instance to be used only for testing.
 * Add a test that exposes the updating issues and covers the fixes

Fixes #774
Fixes #1866
Fixes #3023
2016-01-26 14:46:26 -06:00

64 lines
1.4 KiB
Go

package consul
import (
"os"
"testing"
consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider
func init() {
testAccProvider = Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{
"consul": testAccProvider,
}
// Use the demo address for the acceptance tests
testAccProvider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
conf := consulapi.DefaultConfig()
return consulapi.NewClient(conf)
}
}
func TestResourceProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestResourceProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
func TestResourceProvider_Configure(t *testing.T) {
rp := Provider()
raw := map[string]interface{}{
"address": "demo.consul.io:80",
"datacenter": "nyc3",
"scheme": "https",
}
rawConfig, err := config.NewRawConfig(raw)
if err != nil {
t.Fatalf("err: %s", err)
}
err = rp.Configure(terraform.NewResourceConfig(rawConfig))
if err != nil {
t.Fatalf("err: %s", err)
}
}
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("CONSUL_HTTP_ADDR"); v == "" {
t.Fatal("CONSUL_HTTP_ADDR must be set for acceptance tests")
}
}