2017-03-29 18:30:08 +02:00
|
|
|
package opc
|
|
|
|
|
|
|
|
import (
|
2017-04-04 00:24:53 +02:00
|
|
|
"fmt"
|
2017-03-29 18:30:08 +02:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2017-04-04 00:24:53 +02:00
|
|
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
2017-03-29 18:30:08 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"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{
|
|
|
|
"opc": testAccProvider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvider(t *testing.T) {
|
|
|
|
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
|
2017-04-10 13:28:17 +02:00
|
|
|
t.Fatalf("Error creating Provider: %s", err)
|
2017-03-29 18:30:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvider_impl(t *testing.T) {
|
|
|
|
var _ terraform.ResourceProvider = Provider()
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccPreCheck(t *testing.T) {
|
|
|
|
required := []string{"OPC_USERNAME", "OPC_PASSWORD", "OPC_IDENTITY_DOMAIN", "OPC_ENDPOINT"}
|
|
|
|
for _, prop := range required {
|
|
|
|
if os.Getenv(prop) == "" {
|
|
|
|
t.Fatalf("%s must be set for acceptance test", prop)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type OPCResourceState struct {
|
2017-04-04 00:24:53 +02:00
|
|
|
*compute.Client
|
2017-03-29 18:30:08 +02:00
|
|
|
*terraform.InstanceState
|
|
|
|
}
|
|
|
|
|
|
|
|
func opcResourceCheck(resourceName string, f func(checker *OPCResourceState) error) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[resourceName]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Resource not found: %s", resourceName)
|
|
|
|
}
|
|
|
|
|
|
|
|
state := &OPCResourceState{
|
2017-04-04 00:24:53 +02:00
|
|
|
Client: testAccProvider.Meta().(*compute.Client),
|
2017-03-29 18:30:08 +02:00
|
|
|
InstanceState: rs.Primary,
|
|
|
|
}
|
|
|
|
|
|
|
|
return f(state)
|
|
|
|
}
|
|
|
|
}
|