-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update unit tests to use generated files
And add a test to the json package to make sure the variable output stays consistent between versions.
- Loading branch information
1 parent
c0f5022
commit a595404
Showing
17 changed files
with
101 additions
and
262 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package json | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCreateSchema(t *testing.T) { | ||
t.Parallel() | ||
tfPath := "../../test/modules" | ||
schemaPath := "../../test/expected" | ||
testCases := []string{ | ||
"empty", | ||
"simple", | ||
"simple-types", | ||
"complex-types", | ||
"custom-validation", | ||
} | ||
for i := range testCases { | ||
name := testCases[i] | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
expected, err := os.ReadFile(filepath.Join(schemaPath, name, "variables.json")) | ||
require.NoError(t, err) | ||
|
||
result, err := ExportVariables(filepath.Join(tfPath, name), ExportVariablesOptions{ | ||
AllowEmpty: true, | ||
DebugOut: true, | ||
SuppressLogging: false, | ||
EscapeJSON: false, | ||
Indent: "\t", | ||
}) | ||
require.NoError(t, err) | ||
|
||
// marshal and unmarshal to ensure that the map is in the correct format | ||
buf, err := json.Marshal(result) | ||
require.NoError(t, err) | ||
|
||
var gotMap map[string]any | ||
err = json.Unmarshal(buf, &gotMap) | ||
require.NoError(t, err) | ||
|
||
var expectedMap map[string]any | ||
err = json.Unmarshal(expected, &expectedMap) | ||
require.NoError(t, err) | ||
|
||
if d := cmp.Diff(expectedMap, gotMap); d != "" { | ||
t.Errorf("Schema has incorrect value (-want,+got):\n%s", d) | ||
} | ||
}) | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
test/expected/complex-types/sample-input/test-input-null.json
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,5 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"a_very_complicated_object": null, | ||
"an_object_with_optional": null | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
test/expected/custom-validation/sample-input/test-input-null.json
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,15 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"a_list_maximum_minimum_length": null, | ||
"a_map_maximum_minimum_entries": null, | ||
"a_set_maximum_minimum_items": null, | ||
"a_string_enum_escaped_characters_kind_1": null, | ||
"a_string_enum_kind_1": null, | ||
"a_string_enum_kind_2": null, | ||
"a_string_length_over_defined": null, | ||
"a_string_maximum_minimum_length":null, | ||
"a_string_pattern_1": null, | ||
"a_string_pattern_2": null, | ||
"a_string_set_length":null, | ||
"an_object_maximum_minimum_items": null | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
test/expected/simple-types/sample-input/test-input-null.json
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,13 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"a_bool": null, | ||
"a_list": null, | ||
"a_map_of_strings": null, | ||
"a_nullable_string": null, | ||
"a_number": null, | ||
"a_set": null, | ||
"a_string": null, | ||
"a_tuple": null, | ||
"a_variable_in_another_file": null, | ||
"an_object": null | ||
} |
Oops, something went wrong.