Skip to content

Commit

Permalink
TER-233: Add tests for provider and ghost app resource, add make test…
Browse files Browse the repository at this point in the history
… recipes and add test packages to vendor
  • Loading branch information
Jordan Caussat authored and Jordan Caussat committed Mar 19, 2018
1 parent bf4b9bd commit c2dfba7
Show file tree
Hide file tree
Showing 73 changed files with 21,703 additions and 8 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SOURCEDIR=.
SOURCES := $(shell find $(SOURCEDIR) -name '*.go' | grep -v vendor)
TEST?=./...
BIN_FOLDER=bin/
BINARY=$(BIN_FOLDER)terraform-provider-ghost
VERSION=1.0.0
Expand All @@ -16,7 +17,13 @@ install: fmt
fmt:
gofmt $(SOURCES)

test:
go test $(TEST) -timeout=30s -parallel=4

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

clean:
$(RM) ${BINARY}

.PHONY: install fmt clean
.PHONY: install fmt test clean
43 changes: 43 additions & 0 deletions ghost/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ghost

import (
"os"
"testing"

"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{
"ghost": testAccProvider,
}
}

func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestProviderImpl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}

func testAccPreCheck(t *testing.T) {
if v := os.Getenv("GHOST_USER"); v == "" {
t.Fatal("GHOST_USER must be set for acceptance tests")
}

if v := os.Getenv("GHOST_PASSWORD"); v == "" {
t.Fatal("GHOST_USER must be set for acceptance tests")
}

if v := os.Getenv("GHOST_ENDPOINT"); v == "" {
t.Fatal("GHOST_USER must be set for acceptance tests")
}
}
15 changes: 8 additions & 7 deletions ghost/resource_ghost_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func resourceGhostApp() *schema.Resource {
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
Optional: true,
Default: "elb",
},
"wait_before_deploy": {
Expand All @@ -107,8 +107,9 @@ func resourceGhostApp() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ssh_username": {
Type: schema.TypeString,
Default: "admin",
Type: schema.TypeString,
Optional: true,
Default: "admin",
},
"source_ami": {
Type: schema.TypeString,
Expand Down Expand Up @@ -244,7 +245,7 @@ func resourceGhostApp() *schema.Resource {

"features": {
Type: schema.TypeList,
Required: false,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Expand All @@ -261,7 +262,7 @@ func resourceGhostApp() *schema.Resource {

"lifecycle_hooks": {
Type: schema.TypeList,
Required: false,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -302,11 +303,11 @@ func resourceGhostApp() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"UID": {
"uid": {
Type: schema.TypeString,
Optional: true,
},
"GID": {
"gid": {
Type: schema.TypeString,
Optional: true,
},
Expand Down
81 changes: 81 additions & 0 deletions ghost/resource_ghost_app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ghost

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestGhostAppBasic(t *testing.T) {
resourceName := "ghost_app.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testGhostAppConfig(resourceName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", "wordpress"),
resource.TestCheckResourceAttrSet("env", "dv"),
),
},
},
})
}

func testGhostAppConfig(name string) string {
return fmt.Sprintf(`
resource "ghost_app" "test" {
name = "%s"
env = "dev"
role = "webfront"
region = "eu-west-1"
instance_type = "t2.micro"
vpc_id = "vpc-3f1eb65a"
log_notifications = [
"[email protected]",
]
build_infos = {
subnet_id = "subnet-a7e849fe"
ssh_username = "admin"
source_ami = "ami-03ce4474"
}
environment_infos = {
instance_profile = "iam.ec2.demo"
key_name = "ghost-demo"
root_block_device = {}
optional_volumes = []
subnet_ids = ["subnet-a7e849fe"]
security_groups = ["sg-6814f60c"]
}
autoscale = {
name = ""
}
module = {
name = "symfony2"
pre_deploy = "ZXhpdCAx"
path = "/var/www"
scope = "code"
git_repo = "https://github.com/KnpLabs/KnpIpsum.git"
}
feature = {
version = "5.4"
name = "php5"
}
feature = {
version = "2.2"
name = "apache2"
}
}
`, name)
}
15 changes: 15 additions & 0 deletions vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

145 changes: 145 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c2dfba7

Please sign in to comment.