Skip to content

Commit

Permalink
Add tests for NestedBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Mar 31, 2022
1 parent 46e4495 commit 0975f76
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tfwrite/nested_block_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tfwrite

import (
"testing"
)

func TestNestedBlockType(t *testing.T) {
cases := []struct {
desc string
src string
name string
want string
ok bool
}{
{
desc: "simple",
src: `
foo {
nested {
bar = "baz"
}
}
`,
name: "nested",
want: "nested",
ok: true,
},
}

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
f := parseTestFile(t, tc.src)
b := findFirstTestBlock(t, f)
nestedBlocks := b.FindNestedBlocksByType(tc.name)

got := nestedBlocks[0].Type()
if got != tc.want {
t.Errorf("got = %s, but want = %s", got, tc.want)
}
})
}
}
34 changes: 34 additions & 0 deletions tfwrite/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ import (
"github.com/google/go-cmp/cmp"
)

func TestResourceType(t *testing.T) {
cases := []struct {
desc string
src string
want string
ok bool
}{
{
desc: "simple",
src: `
resource "foo_test" "example" {
nested {
bar = "baz"
}
}
`,
want: "resource",
ok: true,
},
}

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
f := parseTestFile(t, tc.src)
r := findFirstTestResource(t, f)

got := r.Type()
if got != tc.want {
t.Errorf("got = %s, but want = %s", got, tc.want)
}
})
}
}

func TestResourceSchemaType(t *testing.T) {
cases := []struct {
desc string
Expand Down

0 comments on commit 0975f76

Please sign in to comment.