Skip to content

Commit

Permalink
add flattengzip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Apr 20, 2016
1 parent 3f05af7 commit 3639d2d
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions builtin/providers/fastly/resource_fastly_service_v1_gzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,91 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
gofastly "github.com/sethvargo/go-fastly"
)

func TestFastlyServiceV1_FlattenGzips(t *testing.T) {
cases := []struct {
remote []*gofastly.Gzip
local []map[string]interface{}
}{
{
remote: []*gofastly.Gzip{
&gofastly.Gzip{
Name: "someheadder",
Extensions: "css",
},
},
local: []map[string]interface{}{
map[string]interface{}{
"name": "someheadder",
"extensions": schema.NewSet(schema.HashString, []interface{}{"css"}),
},
},
},
{
remote: []*gofastly.Gzip{
&gofastly.Gzip{
Name: "someheadder",
Extensions: "css json js",
ContentTypes: "text/html",
},
},
local: []map[string]interface{}{
map[string]interface{}{
"name": "someheadder",
"extensions": schema.NewSet(schema.HashString, []interface{}{"css", "json", "js"}),
"content_types": schema.NewSet(schema.HashString, []interface{}{"text/html"}),
},
},
},
}

for _, c := range cases {
out := flattenGzips(c.remote)
// loop, because deepequal wont work with our sets
expectedCount := len(c.local)
var found int
for _, o := range out {
for _, l := range c.local {
if o["name"].(string) == l["name"].(string) {
found++
if o["extensions"] == nil && l["extensions"] != nil {
t.Fatalf("output extensions are nil, local are not")
}

if o["extensions"] != nil {
oex := o["extensions"].(*schema.Set)
lex := l["extensions"].(*schema.Set)
if !oex.Equal(lex) {
t.Fatalf("Extensions don't match, expected: %#v, got: %#v", lex, oex)
}
}

if o["content_types"] == nil && l["content_types"] != nil {
t.Fatalf("output content types are nil, local are not")
}

if o["content_types"] != nil {
oct := o["content_types"].(*schema.Set)
lct := l["content_types"].(*schema.Set)
if !oct.Equal(lct) {
t.Fatalf("ContentTypes don't match, expected: %#v, got: %#v", lct, oct)
}
}

}
}
}

if found != expectedCount {
t.Fatalf("Found and expected mismatch: %d / %d", found, expectedCount)
}
}
}

func TestAccFastlyServiceV1_gzips_basic(t *testing.T) {
var service gofastly.ServiceDetail
name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
Expand Down

0 comments on commit 3639d2d

Please sign in to comment.