Skip to content

Commit

Permalink
Update test suite
Browse files Browse the repository at this point in the history
* Build and tear down dependencies instead of relying on resources to
exist (except VPCs, those are time consuming to build)
* Update tests so they pass
* Clean up testing variables; use more hard coded values and depend on
less being provided by tester

Signed-off-by: Stephen Hoekstra <[email protected]>
  • Loading branch information
shoekstra committed Feb 25, 2019
1 parent 92c8a7a commit 57b98e3
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 966 deletions.
155 changes: 8 additions & 147 deletions cosmic/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,113 +60,38 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("COSMIC_SECRET_KEY"); v == "" {
t.Fatal("COSMIC_SECRET_KEY must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_2ND_NIC_IPADDRESS"); v == "" {
t.Fatal("COSMIC_2ND_NIC_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_2ND_NIC_NETWORK"); v == "" {
t.Fatal("COSMIC_2ND_NIC_NETWORK must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_DISK_OFFERING_1"); v == "" {
t.Fatal("COSMIC_DISK_OFFERING_1 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_DISK_OFFERING_2"); v == "" {
t.Fatal("COSMIC_DISK_OFFERING_2 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_HYPERVISOR"); v == "" {
t.Fatal("COSMIC_HYPERVISOR must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_SERVICE_OFFERING_1"); v == "" {
t.Fatal("COSMIC_SERVICE_OFFERING_1 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_SERVICE_OFFERING_2"); v == "" {
t.Fatal("COSMIC_SERVICE_OFFERING_2 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_1"); v == "" {
t.Fatal("COSMIC_NETWORK_1 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_1_IPADDRESS1"); v == "" {
t.Fatal("COSMIC_NETWORK_1_IPADDRESS1 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_1_IPADDRESS2"); v == "" {
t.Fatal("COSMIC_NETWORK_1_IPADDRESS2 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_2"); v == "" {
t.Fatal("COSMIC_NETWORK_2 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_2_CIDR"); v == "" {
t.Fatal("COSMIC_NETWORK_2_CIDR must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_2_GATEWAY"); v == "" {
t.Fatal("COSMIC_NETWORK_2_GATEWAY must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_2_OFFERING"); v == "" {
t.Fatal("COSMIC_NETWORK_2_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_NETWORK_2_IPADDRESS"); v == "" {
t.Fatal("COSMIC_NETWORK_2_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_VPC_CIDR_1"); v == "" {
t.Fatal("COSMIC_VPC_CIDR_1 must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_VPC_CIDR_2"); v == "" {
t.Fatal("COSMIC_VPC_CIDR_2 must be set for acceptance tests")
if v := os.Getenv("COSMIC_VPC_ID"); v == "" {
t.Fatal("COSMIC_VPC_ID must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_VPC_OFFERING"); v == "" {
t.Fatal("COSMIC_VPC_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_VPC_NETWORK_CIDR"); v == "" {
t.Fatal("COSMIC_VPC_NETWORK_CIDR must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_VPC_NETWORK_GATEWAY"); v == "" {
t.Fatal("COSMIC_VPC_NETWORK_GATEWAY must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_VPC_NETWORK_OFFERING"); v == "" {
t.Fatal("COSMIC_VPC_NETWORK_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_VPC_NETWORK_IPADDRESS"); v == "" {
t.Fatal("COSMIC_VPC_NETWORK_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_PUBLIC_IPADDRESS"); v == "" {
t.Fatal("COSMIC_PUBLIC_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_SSH_PUBLIC_KEY"); v == "" {
t.Fatal("COSMIC_SSH_PUBLIC_KEY must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_TEMPLATE"); v == "" {
t.Fatal("COSMIC_TEMPLATE must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_TEMPLATE_FORMAT"); v == "" {
t.Fatal("COSMIC_TEMPLATE_FORMAT must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_TEMPLATE_URL"); v == "" {
t.Fatal("COSMIC_TEMPLATE_URL must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_TEMPLATE_OS_TYPE"); v == "" {
t.Fatal("COSMIC_TEMPLATE_OS_TYPE must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_PROJECT_NAME"); v == "" {
t.Fatal("COSMIC_PROJECT_NAME must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_PROJECT_NETWORK"); v == "" {
t.Fatal("COSMIC_PROJECT_NETWORK must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_ZONE"); v == "" {
t.Fatal("COSMIC_ZONE must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_PRIVNW_CIDR"); v == "" {
t.Fatal("COSMIC_PRIVNW_CIDR must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_PRIVNW_OFFERING"); v == "" {
t.Fatal("COSMIC_PRIVNW_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_PRIVGW_IPADDRESS"); v == "" {
t.Fatal("COSMIC_PRIVGW_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_STATIC_ROUTE_CIDR"); v == "" {
t.Fatal("COSMIC_STATIC_ROUTE_CIDR must be set for acceptance tests")
}
if v := os.Getenv("COSMIC_STATIC_ROUTE_NEXTHOP"); v == "" {
t.Fatal("COSMIC_STATIC_ROUTE_NEXTHOP must be set for acceptance tests")
if v := os.Getenv("COSMIC_DEFAULT_ALLOW_ACL_ID"); v == "" {
t.Fatal("COSMIC_DEFAULT_ALLOW_ACL_ID must be set for acceptance tests")
}
}

Expand All @@ -182,87 +107,23 @@ var COSMIC_SERVICE_OFFERING_1 = os.Getenv("COSMIC_SERVICE_OFFERING_1")
// Name of a service offering that COSMIC_SERVICE_OFFERING_1 can resize to
var COSMIC_SERVICE_OFFERING_2 = os.Getenv("COSMIC_SERVICE_OFFERING_2")

// Name of a network that already exists
var COSMIC_NETWORK_1 = os.Getenv("COSMIC_NETWORK_1")

// A valid IP address in COSMIC_NETWORK_1
var COSMIC_NETWORK_1_IPADDRESS1 = os.Getenv("COSMIC_NETWORK_1_IPADDRESS1")

// A valid IP address in COSMIC_NETWORK_1
var COSMIC_NETWORK_1_IPADDRESS2 = os.Getenv("COSMIC_NETWORK_1_IPADDRESS2")

// Name for a network that will be created
var COSMIC_NETWORK_2 = os.Getenv("COSMIC_NETWORK_2")

// Any range
var COSMIC_NETWORK_2_CIDR = os.Getenv("COSMIC_NETWORK_2_CIDR")

// An IP address in COSMIC_NETWORK_2_CIDR to be used as the gateway
var COSMIC_NETWORK_2_GATEWAY = os.Getenv("COSMIC_NETWORK_2_GATEWAY")

// Name of an available network offering with specifyvlan=false
var COSMIC_NETWORK_2_OFFERING = os.Getenv("COSMIC_NETWORK_2_OFFERING")

// An IP address in COSMIC_NETWORK_2_CIDR
var COSMIC_NETWORK_2_IPADDRESS = os.Getenv("COSMIC_NETWORK_2_IPADDRESS")

// A network that already exists and isn't COSMIC_NETWORK_1
var COSMIC_2ND_NIC_NETWORK = os.Getenv("COSMIC_2ND_NIC_NETWORK")

// An IP address in COSMIC_2ND_NIC_NETWORK
var COSMIC_2ND_NIC_IPADDRESS = os.Getenv("COSMIC_2ND_NIC_IPADDRESS")

// Any range
var COSMIC_VPC_CIDR_1 = os.Getenv("COSMIC_VPC_CIDR_1")

// Any range that doesn't overlap to COSMIC_VPC_CIDR_1, will be VPNed
var COSMIC_VPC_CIDR_2 = os.Getenv("COSMIC_VPC_CIDR_2")
// ID of an existing VPC
var COSMIC_VPC_ID = os.Getenv("COSMIC_VPC_ID")

// An available VPC offering
var COSMIC_VPC_OFFERING = os.Getenv("COSMIC_VPC_OFFERING")

// A sub-range of COSMIC_VPC_CIDR_1 with same starting point
var COSMIC_VPC_NETWORK_CIDR = os.Getenv("COSMIC_VPC_NETWORK_CIDR")

// A sub-range of COSMIC_VPC_CIDR_1 with same starting point
var COSMIC_VPC_NETWORK_GATEWAY = os.Getenv("COSMIC_VPC_NETWORK_GATEWAY")

// Name of an available network offering with forvpc=true
var COSMIC_VPC_NETWORK_OFFERING = os.Getenv("COSMIC_VPC_NETWORK_OFFERING")

// An IP address in the range of the COSMIC_VPC_NETWORK_CIDR
var COSMIC_VPC_NETWORK_IPADDRESS = os.Getenv("COSMIC_VPC_NETWORK_IPADDRESS")

// Path to a public IP that exists for COSMIC_NETWORK_1
var COSMIC_PUBLIC_IPADDRESS = os.Getenv("COSMIC_PUBLIC_IPADDRESS")

// Path to a public key on local disk
var COSMIC_SSH_PUBLIC_KEY = os.Getenv("COSMIC_SSH_PUBLIC_KEY")

// Name of a template that exists already for building VMs
var COSMIC_TEMPLATE = os.Getenv("COSMIC_TEMPLATE")

// Details of a template that will be added
var COSMIC_TEMPLATE_FORMAT = os.Getenv("COSMIC_TEMPLATE_FORMAT")
var COSMIC_HYPERVISOR = os.Getenv("COSMIC_HYPERVISOR")
var COSMIC_TEMPLATE_URL = os.Getenv("COSMIC_TEMPLATE_URL")
var COSMIC_TEMPLATE_OS_TYPE = os.Getenv("COSMIC_TEMPLATE_OS_TYPE")

// Name of a project that exists already
var COSMIC_PROJECT_NAME = os.Getenv("COSMIC_PROJECT_NAME")

// Name of a network that exists already in COSMIC_PROJECT_NAME
var COSMIC_PROJECT_NETWORK = os.Getenv("COSMIC_PROJECT_NETWORK")

// Name of a zone that exists already
var COSMIC_ZONE = os.Getenv("COSMIC_ZONE")

// Details of the private gateway that will be created
var COSMIC_PRIVNW_CIDR = os.Getenv("COSMIC_PRIVNW_CIDR")
var COSMIC_PRIVNW_OFFERING = os.Getenv("COSMIC_PRIVNW_OFFERING")
var COSMIC_PRIVGW_IPADDRESS = os.Getenv("COSMIC_PRIVGW_IPADDRESS")

// Details of the static route that will be added to private gateway testing this.
// nexthop should be in COSMIC_PRIVNW_CIDR
var COSMIC_STATIC_ROUTE_CIDR = os.Getenv("COSMIC_STATIC_ROUTE_CIDR")
var COSMIC_STATIC_ROUTE_NEXTHOP = os.Getenv("COSMIC_STATIC_ROUTE_NEXTHOP")
// ID of the "default_acl" built-in ACL
var COSMIC_DEFAULT_ALLOW_ACL_ID = os.Getenv("COSMIC_DEFAULT_ALLOW_ACL_ID")
6 changes: 3 additions & 3 deletions cosmic/resource_cosmic_affinity_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccCosmicAffinityGroup_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckCosmicAffinityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccCosmicAffinityGroup,
Check: resource.ComposeTestCheckFunc(
testAccCheckCosmicAffinityGroupExists("cosmic_affinity_group.foo", &affinityGroup),
Expand Down Expand Up @@ -98,8 +98,8 @@ func testAccCheckCosmicAffinityGroupDestroy(s *terraform.State) error {
return nil
}

var testAccCosmicAffinityGroup = fmt.Sprintf(`
const testAccCosmicAffinityGroup = `
resource "cosmic_affinity_group" "foo" {
name = "terraform-affinity-group"
type = "host anti-affinity"
}`)
}`
Loading

0 comments on commit 57b98e3

Please sign in to comment.