-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from drlau/parse-test
add a parse test
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package tfplanparse | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestParse(t *testing.T) { | ||
cases := map[string]struct { | ||
file string | ||
expected []*ResourceChange | ||
}{ | ||
// "basic plan": { | ||
// file: "test/basic.stdout", | ||
// expected: []*ResourceChange{ | ||
// // TODO | ||
// }, | ||
// }, | ||
// "plan error": { | ||
// file: "test/error.stdout", | ||
// expected: nil, | ||
// }, | ||
// "no changes": { | ||
// file: "test/nochanges.stdout", | ||
// expected: nil, | ||
// }, | ||
// "array": { | ||
// file: "test/array.stdout", | ||
// expected: []*ResourceChange{ | ||
// // TODO | ||
// }, | ||
// }, | ||
"nested map": { | ||
file: "test/nestedmap.stdout", | ||
expected: []*ResourceChange{ | ||
&ResourceChange{ | ||
Address: "module.mymodule.kubernetes_namespace.mynamespace", | ||
ModuleAddress: "module.mymodule", | ||
Type: "kubernetes_namespace", | ||
Name: "mynamespace", | ||
UpdateType: UpdateInPlaceResource, | ||
AttributeChanges: nil, | ||
MapAttributeChanges: []*MapAttributeChange{ | ||
&MapAttributeChange{ | ||
Name: "metadata", | ||
AttributeChanges: nil, | ||
MapAttributeChanges: []*MapAttributeChange{ | ||
&MapAttributeChange{ | ||
Name: "labels", | ||
AttributeChanges: []*AttributeChange{ | ||
&AttributeChange{ | ||
Name: "newLabel", | ||
OldValue: nil, | ||
NewValue: "newLabel", | ||
UpdateType: NewResource, | ||
}, | ||
}, | ||
MapAttributeChanges: nil, | ||
UpdateType: UpdateInPlaceResource, | ||
}, | ||
}, | ||
UpdateType: UpdateInPlaceResource, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
// TODO handle expected error | ||
got, err := ParseFromFile(tc.file) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff := cmp.Diff(got, tc.expected); diff != "" { | ||
t.Errorf("(-got, +expected)\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
------------------------------------------------------------------------ | ||
|
||
An execution plan has been generated and is shown below. | ||
Resource actions are indicated with the following symbols: | ||
~ update in-place | ||
|
||
Terraform will perform the following actions: | ||
|
||
# module.mymodule.kubernetes_namespace.mynamespace will be updated in-place | ||
~ resource "kubernetes_namespace" "mynamespace" { | ||
id = "namespace-id" | ||
|
||
~ metadata { | ||
annotations = {} | ||
generation = 0 | ||
~ labels = { | ||
"label" = "value" | ||
"other" = "label" | ||
+ "newLabel" = "newLabel" | ||
} | ||
name = "my-namespace" | ||
resource_version = "123" | ||
self_link = "/api/v1/namespaces/my-namespace" | ||
uid = "some-uid-123" | ||
} | ||
|
||
timeouts {} | ||
} | ||
|
||
Plan: 0 to add, 1 to change, 0 to destroy. |