Skip to content

Commit

Permalink
Merge pull request #39 from MissionCriticalCloud/update_acc_tests
Browse files Browse the repository at this point in the history
Update acceptance tests
  • Loading branch information
ddegoede authored Feb 26, 2019
2 parents 60423a0 + 7e56909 commit 0ebedf6
Show file tree
Hide file tree
Showing 32 changed files with 913 additions and 2,748 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## Unreleased

- Add option to configure provider using `COSMIC_CONFIG` and `COSMIC_PROFILE` environment variables
- Changing `cosmic_loadbalancer_rule`'s `member_ids`, `private_port`, `public_port` or `protocol` options no longer recreates the resource
- Changing `cosmic_network`'s `ip_exclusion_list` option no longer recreates the resource
- Changing `cosmic_vpc`'s `vpc_offering` option no longer recreates the resource
- Removed `cosmic_egress_firewall` and `cosmic_firewall` resources; no longer implemented by the Cosmic API

## 0.1.0 (2019-01-27)

Expand Down
60 changes: 60 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
TEST?=$$(go list ./... | grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=cosmic

default: build

build: fmtcheck
go install

test: fmtcheck
go test -i $(TEST) || exit 1
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout=60m

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

fmt:
gofmt -w $(GOFMT_FILES)

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)

website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test

2 changes: 0 additions & 2 deletions cosmic/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ func Provider() terraform.ResourceProvider {
ResourcesMap: map[string]*schema.Resource{
"cosmic_affinity_group": resourceCosmicAffinityGroup(),
"cosmic_disk": resourceCosmicDisk(),
"cosmic_egress_firewall": resourceCosmicEgressFirewall(),
"cosmic_firewall": resourceCosmicFirewall(),
"cosmic_instance": resourceCosmicInstance(),
"cosmic_ipaddress": resourceCosmicIPAddress(),
"cosmic_loadbalancer_rule": resourceCosmicLoadBalancerRule(),
Expand Down
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")
10 changes: 5 additions & 5 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"
}`)
name = "terraform-affinity-group"
type = "host anti-affinity"
}`
Loading

0 comments on commit 0ebedf6

Please sign in to comment.