github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/cloudstack/provider_test.go (about)

     1  package cloudstack
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/schema"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  var testAccProviders map[string]terraform.ResourceProvider
    12  var testAccProvider *schema.Provider
    13  
    14  func init() {
    15  	testAccProvider = Provider().(*schema.Provider)
    16  	testAccProviders = map[string]terraform.ResourceProvider{
    17  		"cloudstack": testAccProvider,
    18  	}
    19  }
    20  
    21  func TestProvider(t *testing.T) {
    22  	if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
    23  		t.Fatalf("err: %s", err)
    24  	}
    25  }
    26  
    27  func TestProvider_impl(t *testing.T) {
    28  	var _ terraform.ResourceProvider = Provider()
    29  }
    30  
    31  func testSetValueOnResourceData(t *testing.T) {
    32  	d := schema.ResourceData{}
    33  	d.Set("id", "name")
    34  
    35  	setValueOrID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
    36  
    37  	if d.Get("id").(string) != "name" {
    38  		t.Fatal("err: 'id' does not match 'name'")
    39  	}
    40  }
    41  
    42  func testSetIDOnResourceData(t *testing.T) {
    43  	d := schema.ResourceData{}
    44  	d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7")
    45  
    46  	setValueOrID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
    47  
    48  	if d.Get("id").(string) != "54711781-274e-41b2-83c0-17194d0108f7" {
    49  		t.Fatal("err: 'id' doest not match '54711781-274e-41b2-83c0-17194d0108f7'")
    50  	}
    51  }
    52  
    53  func testAccPreCheck(t *testing.T) {
    54  	if v := os.Getenv("CLOUDSTACK_API_URL"); v == "" {
    55  		t.Fatal("CLOUDSTACK_API_URL must be set for acceptance tests")
    56  	}
    57  	if v := os.Getenv("CLOUDSTACK_API_KEY"); v == "" {
    58  		t.Fatal("CLOUDSTACK_API_KEY must be set for acceptance tests")
    59  	}
    60  	if v := os.Getenv("CLOUDSTACK_SECRET_KEY"); v == "" {
    61  		t.Fatal("CLOUDSTACK_SECRET_KEY must be set for acceptance tests")
    62  	}
    63  	if v := os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS"); v == "" {
    64  		t.Fatal("CLOUDSTACK_2ND_NIC_IPADDRESS must be set for acceptance tests")
    65  	}
    66  	if v := os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK"); v == "" {
    67  		t.Fatal("CLOUDSTACK_2ND_NIC_NETWORK must be set for acceptance tests")
    68  	}
    69  	if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_1"); v == "" {
    70  		t.Fatal("CLOUDSTACK_DISK_OFFERING_1 must be set for acceptance tests")
    71  	}
    72  	if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_2"); v == "" {
    73  		t.Fatal("CLOUDSTACK_DISK_OFFERING_2 must be set for acceptance tests")
    74  	}
    75  	if v := os.Getenv("CLOUDSTACK_HYPERVISOR"); v == "" {
    76  		t.Fatal("CLOUDSTACK_HYPERVISOR must be set for acceptance tests")
    77  	}
    78  	if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1"); v == "" {
    79  		t.Fatal("CLOUDSTACK_SERVICE_OFFERING_1 must be set for acceptance tests")
    80  	}
    81  	if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2"); v == "" {
    82  		t.Fatal("CLOUDSTACK_SERVICE_OFFERING_2 must be set for acceptance tests")
    83  	}
    84  	if v := os.Getenv("CLOUDSTACK_NETWORK_1"); v == "" {
    85  		t.Fatal("CLOUDSTACK_NETWORK_1 must be set for acceptance tests")
    86  	}
    87  	if v := os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS"); v == "" {
    88  		t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS must be set for acceptance tests")
    89  	}
    90  	if v := os.Getenv("CLOUDSTACK_NETWORK_2"); v == "" {
    91  		t.Fatal("CLOUDSTACK_NETWORK_2 must be set for acceptance tests")
    92  	}
    93  	if v := os.Getenv("CLOUDSTACK_NETWORK_2_CIDR"); v == "" {
    94  		t.Fatal("CLOUDSTACK_NETWORK_2_CIDR must be set for acceptance tests")
    95  	}
    96  	if v := os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING"); v == "" {
    97  		t.Fatal("CLOUDSTACK_NETWORK_2_OFFERING must be set for acceptance tests")
    98  	}
    99  	if v := os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS"); v == "" {
   100  		t.Fatal("CLOUDSTACK_NETWORK_2_IPADDRESS must be set for acceptance tests")
   101  	}
   102  	if v := os.Getenv("CLOUDSTACK_VPC_CIDR_1"); v == "" {
   103  		t.Fatal("CLOUDSTACK_VPC_CIDR_1 must be set for acceptance tests")
   104  	}
   105  	if v := os.Getenv("CLOUDSTACK_VPC_CIDR_2"); v == "" {
   106  		t.Fatal("CLOUDSTACK_VPC_CIDR_2 must be set for acceptance tests")
   107  	}
   108  	if v := os.Getenv("CLOUDSTACK_VPC_OFFERING"); v == "" {
   109  		t.Fatal("CLOUDSTACK_VPC_OFFERING must be set for acceptance tests")
   110  	}
   111  	if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR"); v == "" {
   112  		t.Fatal("CLOUDSTACK_VPC_NETWORK_CIDR must be set for acceptance tests")
   113  	}
   114  	if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING"); v == "" {
   115  		t.Fatal("CLOUDSTACK_VPC_NETWORK_OFFERING must be set for acceptance tests")
   116  	}
   117  	if v := os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS"); v == "" {
   118  		t.Fatal("CLOUDSTACK_PUBLIC_IPADDRESS must be set for acceptance tests")
   119  	}
   120  	if v := os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY"); v == "" {
   121  		t.Fatal("CLOUDSTACK_SSH_PUBLIC_KEY must be set for acceptance tests")
   122  	}
   123  	if v := os.Getenv("CLOUDSTACK_TEMPLATE"); v == "" {
   124  		t.Fatal("CLOUDSTACK_TEMPLATE must be set for acceptance tests")
   125  	}
   126  	if v := os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT"); v == "" {
   127  		t.Fatal("CLOUDSTACK_TEMPLATE_FORMAT must be set for acceptance tests")
   128  	}
   129  	if v := os.Getenv("CLOUDSTACK_TEMPLATE_URL"); v == "" {
   130  		t.Fatal("CLOUDSTACK_TEMPLATE_URL must be set for acceptance tests")
   131  	}
   132  	if v := os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE"); v == "" {
   133  		t.Fatal("CLOUDSTACK_TEMPLATE_OS_TYPE must be set for acceptance tests")
   134  	}
   135  	if v := os.Getenv("CLOUDSTACK_PROJECT_NAME"); v == "" {
   136  		t.Fatal("CLOUDSTACK_PROJECT_NAME must be set for acceptance tests")
   137  	}
   138  	if v := os.Getenv("CLOUDSTACK_PROJECT_NETWORK"); v == "" {
   139  		t.Fatal("CLOUDSTACK_PROJECT_NETWORK must be set for acceptance tests")
   140  	}
   141  	if v := os.Getenv("CLOUDSTACK_ZONE"); v == "" {
   142  		t.Fatal("CLOUDSTACK_ZONE must be set for acceptance tests")
   143  	}
   144  }
   145  
   146  // Name of a valid disk offering
   147  var CLOUDSTACK_DISK_OFFERING_1 = os.Getenv("CLOUDSTACK_DISK_OFFERING_1")
   148  
   149  // Name of a disk offering that CLOUDSTACK_DISK_OFFERING_1 can resize to
   150  var CLOUDSTACK_DISK_OFFERING_2 = os.Getenv("CLOUDSTACK_DISK_OFFERING_2")
   151  
   152  // Name of a valid service offering
   153  var CLOUDSTACK_SERVICE_OFFERING_1 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1")
   154  
   155  // Name of a service offering that CLOUDSTACK_SERVICE_OFFERING_1 can resize to
   156  var CLOUDSTACK_SERVICE_OFFERING_2 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2")
   157  
   158  // Name of a network that already exists
   159  var CLOUDSTACK_NETWORK_1 = os.Getenv("CLOUDSTACK_NETWORK_1")
   160  
   161  // A valid IP address in CLOUDSTACK_NETWORK_1
   162  var CLOUDSTACK_NETWORK_1_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS")
   163  
   164  // Name for a network that will be created
   165  var CLOUDSTACK_NETWORK_2 = os.Getenv("CLOUDSTACK_NETWORK_2")
   166  
   167  // Any range
   168  var CLOUDSTACK_NETWORK_2_CIDR = os.Getenv("CLOUDSTACK_NETWORK_2_CIDR")
   169  
   170  // Name of an available network offering with specifyvlan=false
   171  var CLOUDSTACK_NETWORK_2_OFFERING = os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING")
   172  
   173  // An IP address in CLOUDSTACK_NETWORK_2_CIDR
   174  var CLOUDSTACK_NETWORK_2_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS")
   175  
   176  // A network that already exists and isn't CLOUDSTACK_NETWORK_1
   177  var CLOUDSTACK_2ND_NIC_NETWORK = os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK")
   178  
   179  // An IP address in CLOUDSTACK_2ND_NIC_NETWORK
   180  var CLOUDSTACK_2ND_NIC_IPADDRESS = os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS")
   181  
   182  // Any range
   183  var CLOUDSTACK_VPC_CIDR_1 = os.Getenv("CLOUDSTACK_VPC_CIDR_1")
   184  
   185  // Any range that doesn't overlap to CLOUDSTACK_VPC_CIDR_1, will be VPNed
   186  var CLOUDSTACK_VPC_CIDR_2 = os.Getenv("CLOUDSTACK_VPC_CIDR_2")
   187  
   188  // An available VPC offering
   189  var CLOUDSTACK_VPC_OFFERING = os.Getenv("CLOUDSTACK_VPC_OFFERING")
   190  
   191  // A sub-range of CLOUDSTACK_VPC_CIDR_1 with same starting point
   192  var CLOUDSTACK_VPC_NETWORK_CIDR = os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR")
   193  
   194  // Name of an available network offering with forvpc=true
   195  var CLOUDSTACK_VPC_NETWORK_OFFERING = os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING")
   196  
   197  // Path to a public IP that exists for CLOUDSTACK_NETWORK_1
   198  var CLOUDSTACK_PUBLIC_IPADDRESS = os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS")
   199  
   200  // Path to a public key on local disk
   201  var CLOUDSTACK_SSH_PUBLIC_KEY = os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY")
   202  
   203  // Name of a template that exists already for building VMs
   204  var CLOUDSTACK_TEMPLATE = os.Getenv("CLOUDSTACK_TEMPLATE")
   205  
   206  // Details of a template that will be added
   207  var CLOUDSTACK_TEMPLATE_FORMAT = os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT")
   208  var CLOUDSTACK_HYPERVISOR = os.Getenv("CLOUDSTACK_HYPERVISOR")
   209  var CLOUDSTACK_TEMPLATE_URL = os.Getenv("CLOUDSTACK_TEMPLATE_URL")
   210  var CLOUDSTACK_TEMPLATE_OS_TYPE = os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE")
   211  
   212  // Name of a project that exists already
   213  var CLOUDSTACK_PROJECT_NAME = os.Getenv("CLOUDSTACK_PROJECT_NAME")
   214  
   215  // Name of a network that exists already in CLOUDSTACK_PROJECT_NAME
   216  var CLOUDSTACK_PROJECT_NETWORK = os.Getenv("CLOUDSTACK_PROJECT_NETWORK")
   217  
   218  // Name of a zone that exists already
   219  var CLOUDSTACK_ZONE = os.Getenv("CLOUDSTACK_ZONE")