github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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_IPADDRESS1"); v == "" {
    88  		t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS1 must be set for acceptance tests")
    89  	}
    90  	if v := os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS2"); v == "" {
    91  		t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS2 must be set for acceptance tests")
    92  	}
    93  	if v := os.Getenv("CLOUDSTACK_NETWORK_2"); v == "" {
    94  		t.Fatal("CLOUDSTACK_NETWORK_2 must be set for acceptance tests")
    95  	}
    96  	if v := os.Getenv("CLOUDSTACK_NETWORK_2_CIDR"); v == "" {
    97  		t.Fatal("CLOUDSTACK_NETWORK_2_CIDR must be set for acceptance tests")
    98  	}
    99  	if v := os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING"); v == "" {
   100  		t.Fatal("CLOUDSTACK_NETWORK_2_OFFERING must be set for acceptance tests")
   101  	}
   102  	if v := os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS"); v == "" {
   103  		t.Fatal("CLOUDSTACK_NETWORK_2_IPADDRESS must be set for acceptance tests")
   104  	}
   105  	if v := os.Getenv("CLOUDSTACK_VPC_CIDR_1"); v == "" {
   106  		t.Fatal("CLOUDSTACK_VPC_CIDR_1 must be set for acceptance tests")
   107  	}
   108  	if v := os.Getenv("CLOUDSTACK_VPC_CIDR_2"); v == "" {
   109  		t.Fatal("CLOUDSTACK_VPC_CIDR_2 must be set for acceptance tests")
   110  	}
   111  	if v := os.Getenv("CLOUDSTACK_VPC_OFFERING"); v == "" {
   112  		t.Fatal("CLOUDSTACK_VPC_OFFERING must be set for acceptance tests")
   113  	}
   114  	if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR"); v == "" {
   115  		t.Fatal("CLOUDSTACK_VPC_NETWORK_CIDR must be set for acceptance tests")
   116  	}
   117  	if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING"); v == "" {
   118  		t.Fatal("CLOUDSTACK_VPC_NETWORK_OFFERING must be set for acceptance tests")
   119  	}
   120  	if v := os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS"); v == "" {
   121  		t.Fatal("CLOUDSTACK_PUBLIC_IPADDRESS must be set for acceptance tests")
   122  	}
   123  	if v := os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY"); v == "" {
   124  		t.Fatal("CLOUDSTACK_SSH_PUBLIC_KEY must be set for acceptance tests")
   125  	}
   126  	if v := os.Getenv("CLOUDSTACK_TEMPLATE"); v == "" {
   127  		t.Fatal("CLOUDSTACK_TEMPLATE must be set for acceptance tests")
   128  	}
   129  	if v := os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT"); v == "" {
   130  		t.Fatal("CLOUDSTACK_TEMPLATE_FORMAT must be set for acceptance tests")
   131  	}
   132  	if v := os.Getenv("CLOUDSTACK_TEMPLATE_URL"); v == "" {
   133  		t.Fatal("CLOUDSTACK_TEMPLATE_URL must be set for acceptance tests")
   134  	}
   135  	if v := os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE"); v == "" {
   136  		t.Fatal("CLOUDSTACK_TEMPLATE_OS_TYPE must be set for acceptance tests")
   137  	}
   138  	if v := os.Getenv("CLOUDSTACK_PROJECT_NAME"); v == "" {
   139  		t.Fatal("CLOUDSTACK_PROJECT_NAME must be set for acceptance tests")
   140  	}
   141  	if v := os.Getenv("CLOUDSTACK_PROJECT_NETWORK"); v == "" {
   142  		t.Fatal("CLOUDSTACK_PROJECT_NETWORK must be set for acceptance tests")
   143  	}
   144  	if v := os.Getenv("CLOUDSTACK_ZONE"); v == "" {
   145  		t.Fatal("CLOUDSTACK_ZONE must be set for acceptance tests")
   146  	}
   147  	if v := os.Getenv("CLOUDSTACK_PRIVGW_GATEWAY"); v == "" {
   148  		t.Fatal("CLOUDSTACK_PRIVGW_GATEWAY must be set for acceptance tests")
   149  	}
   150  	if v := os.Getenv("CLOUDSTACK_PRIVGW_IPADDRESS"); v == "" {
   151  		t.Fatal("CLOUDSTACK_PRIVGW_IPADDRESS must be set for acceptance tests")
   152  	}
   153  	if v := os.Getenv("CLOUDSTACK_PRIVGW_NETMASK"); v == "" {
   154  		t.Fatal("CLOUDSTACK_PRIVGW_NETMASK must be set for acceptance tests")
   155  	}
   156  	if v := os.Getenv("CLOUDSTACK_PRIVGW_VLAN"); v == "" {
   157  		t.Fatal("CLOUDSTACK_PRIVGW_VLAN must be set for acceptance tests")
   158  	}
   159  	if v := os.Getenv("CLOUDSTACK_STATIC_ROUTE_CIDR"); v == "" {
   160  		t.Fatal("CLOUDSTACK_STATIC_ROUTE_CIDR must be set for acceptance tests")
   161  	}
   162  }
   163  
   164  // Name of a valid disk offering
   165  var CLOUDSTACK_DISK_OFFERING_1 = os.Getenv("CLOUDSTACK_DISK_OFFERING_1")
   166  
   167  // Name of a disk offering that CLOUDSTACK_DISK_OFFERING_1 can resize to
   168  var CLOUDSTACK_DISK_OFFERING_2 = os.Getenv("CLOUDSTACK_DISK_OFFERING_2")
   169  
   170  // Name of a valid service offering
   171  var CLOUDSTACK_SERVICE_OFFERING_1 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1")
   172  
   173  // Name of a service offering that CLOUDSTACK_SERVICE_OFFERING_1 can resize to
   174  var CLOUDSTACK_SERVICE_OFFERING_2 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2")
   175  
   176  // Name of a network that already exists
   177  var CLOUDSTACK_NETWORK_1 = os.Getenv("CLOUDSTACK_NETWORK_1")
   178  
   179  // A valid IP address in CLOUDSTACK_NETWORK_1
   180  var CLOUDSTACK_NETWORK_1_IPADDRESS1 = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS1")
   181  
   182  // A valid IP address in CLOUDSTACK_NETWORK_1
   183  var CLOUDSTACK_NETWORK_1_IPADDRESS2 = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS2")
   184  
   185  // Name for a network that will be created
   186  var CLOUDSTACK_NETWORK_2 = os.Getenv("CLOUDSTACK_NETWORK_2")
   187  
   188  // Any range
   189  var CLOUDSTACK_NETWORK_2_CIDR = os.Getenv("CLOUDSTACK_NETWORK_2_CIDR")
   190  
   191  // Name of an available network offering with specifyvlan=false
   192  var CLOUDSTACK_NETWORK_2_OFFERING = os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING")
   193  
   194  // An IP address in CLOUDSTACK_NETWORK_2_CIDR
   195  var CLOUDSTACK_NETWORK_2_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS")
   196  
   197  // A network that already exists and isn't CLOUDSTACK_NETWORK_1
   198  var CLOUDSTACK_2ND_NIC_NETWORK = os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK")
   199  
   200  // An IP address in CLOUDSTACK_2ND_NIC_NETWORK
   201  var CLOUDSTACK_2ND_NIC_IPADDRESS = os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS")
   202  
   203  // Any range
   204  var CLOUDSTACK_VPC_CIDR_1 = os.Getenv("CLOUDSTACK_VPC_CIDR_1")
   205  
   206  // Any range that doesn't overlap to CLOUDSTACK_VPC_CIDR_1, will be VPNed
   207  var CLOUDSTACK_VPC_CIDR_2 = os.Getenv("CLOUDSTACK_VPC_CIDR_2")
   208  
   209  // An available VPC offering
   210  var CLOUDSTACK_VPC_OFFERING = os.Getenv("CLOUDSTACK_VPC_OFFERING")
   211  
   212  // A sub-range of CLOUDSTACK_VPC_CIDR_1 with same starting point
   213  var CLOUDSTACK_VPC_NETWORK_CIDR = os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR")
   214  
   215  // Name of an available network offering with forvpc=true
   216  var CLOUDSTACK_VPC_NETWORK_OFFERING = os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING")
   217  
   218  // Path to a public IP that exists for CLOUDSTACK_NETWORK_1
   219  var CLOUDSTACK_PUBLIC_IPADDRESS = os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS")
   220  
   221  // Path to a public key on local disk
   222  var CLOUDSTACK_SSH_PUBLIC_KEY = os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY")
   223  
   224  // Name of a template that exists already for building VMs
   225  var CLOUDSTACK_TEMPLATE = os.Getenv("CLOUDSTACK_TEMPLATE")
   226  
   227  // Details of a template that will be added
   228  var CLOUDSTACK_TEMPLATE_FORMAT = os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT")
   229  var CLOUDSTACK_HYPERVISOR = os.Getenv("CLOUDSTACK_HYPERVISOR")
   230  var CLOUDSTACK_TEMPLATE_URL = os.Getenv("CLOUDSTACK_TEMPLATE_URL")
   231  var CLOUDSTACK_TEMPLATE_OS_TYPE = os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE")
   232  
   233  // Name of a project that exists already
   234  var CLOUDSTACK_PROJECT_NAME = os.Getenv("CLOUDSTACK_PROJECT_NAME")
   235  
   236  // Name of a network that exists already in CLOUDSTACK_PROJECT_NAME
   237  var CLOUDSTACK_PROJECT_NETWORK = os.Getenv("CLOUDSTACK_PROJECT_NETWORK")
   238  
   239  // Name of a zone that exists already
   240  var CLOUDSTACK_ZONE = os.Getenv("CLOUDSTACK_ZONE")
   241  
   242  // Details of the private gateway that will be added to VPC testing this, should be done using ROOT keys
   243  var CLOUDSTACK_PRIVGW_GATEWAY = os.Getenv("CLOUDSTACK_PRIVGW_GATEWAY")
   244  var CLOUDSTACK_PRIVGW_IPADDRESS = os.Getenv("CLOUDSTACK_PRIVGW_IPADDRESS")
   245  var CLOUDSTACK_PRIVGW_NETMASK = os.Getenv("CLOUDSTACK_PRIVGW_NETMASK")
   246  var CLOUDSTACK_PRIVGW_VLAN = os.Getenv("CLOUDSTACK_PRIVGW_VLAN")
   247  
   248  // Details of the static route that will be added to private gateway testing this.
   249  var CLOUDSTACK_STATIC_ROUTE_CIDR = os.Getenv("CLOUDSTACK_STATIC_ROUTE_CIDR")