75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package provider
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
|
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
|
|
|
"github.com/paultyng/terraform-provider-unifi/unifi"
|
|
)
|
|
|
|
var providers map[string]terraform.ResourceProvider
|
|
var testClient *unifi.Client
|
|
|
|
func TestMain(m *testing.M) {
|
|
if os.Getenv("TF_ACC") == "" {
|
|
// short circuit non acceptance test runs
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
providers = map[string]terraform.ResourceProvider{
|
|
"unifi": Provider(),
|
|
}
|
|
|
|
user := os.Getenv("UNIFI_USERNAME")
|
|
pass := os.Getenv("UNIFI_PASSWORD")
|
|
baseURL := os.Getenv("UNIFI_API")
|
|
|
|
testClient = &unifi.Client{}
|
|
testClient.SetBaseURL(baseURL)
|
|
err := testClient.Login(user, pass)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestProvider(t *testing.T) {
|
|
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
func importStep(name string, ignore ...string) resource.TestStep {
|
|
step := resource.TestStep{
|
|
ResourceName: name,
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
}
|
|
|
|
if len(ignore) > 0 {
|
|
step.ImportStateVerifyIgnore = ignore
|
|
}
|
|
|
|
return step
|
|
}
|
|
|
|
func preCheck(t *testing.T) {
|
|
variables := []string{
|
|
"UNIFI_USERNAME",
|
|
"UNIFI_PASSWORD",
|
|
"UNIFI_API",
|
|
}
|
|
|
|
for _, variable := range variables {
|
|
value := os.Getenv(variable)
|
|
if value == "" {
|
|
t.Fatalf("`%s` must be set for acceptance tests!", variable)
|
|
}
|
|
}
|
|
}
|