Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a75888c
Incorporating usage of spec element type
bendbennett Jun 6, 2023
88cfa48
Adding tests for custom types on elements
bendbennett Jun 6, 2023
8eca8e4
Updating ci-go.yml to use token for pulling modules from codegen-spec…
bendbennett Jun 6, 2023
f616f4e
Linting
bendbennett Jun 6, 2023
f685238
Merge branch 'main' into schema-provider-resources
bendbennett Jun 7, 2023
ea638cc
Using latest version of main and calling spec.Parse for validation an…
bendbennett Jun 7, 2023
237dd34
Switching to using HasImport available in spec
bendbennett Jun 7, 2023
a006f7a
Add handling of element type and attribute type into provider and res…
bendbennett Jun 7, 2023
d880e52
Add handling of default and plan modifier imports into resources
bendbennett Jun 8, 2023
aa76ba8
Switching to using HasImport() helper method
bendbennett Jun 8, 2023
b337d8c
Removing unused function
bendbennett Jun 8, 2023
4c3a606
Wiring-up addition of imports into schema template for provider and r…
bendbennett Jun 8, 2023
8226f2e
Removing unneeded schemaImport inclusion in import generation as the …
bendbennett Jun 8, 2023
c3863f1
Moving commands to separate directory
bendbennett May 30, 2023
a592e5d
Adding new line when object contains more than one attribute type
bendbennett Jun 8, 2023
ec90ac6
Adding copyright headers
bendbennett Jun 8, 2023
d734561
Handling custom type in schema generation for collection elements and…
bendbennett Jun 9, 2023
61a3099
Amending golangci configuration to skip output directory
bendbennett Jun 9, 2023
0654f06
Refactoring to used shared functions for spec schema ElementType and …
bendbennett Jun 9, 2023
7ec0d8b
Merge branch 'main' into av/e2e-tests
austinvalle Jun 15, 2023
8030051
generate some testdata
austinvalle Jun 15, 2023
99fb3d8
small fix to config args
austinvalle Jun 15, 2023
6ba7fe6
remove example
austinvalle Jun 15, 2023
f19c352
rename golden
austinvalle Jun 16, 2023
743e08a
rename folder
austinvalle Jun 16, 2023
dee6a2d
add test
austinvalle Jun 16, 2023
451f496
update makefile
austinvalle Jun 16, 2023
ff9a2be
Merge branch 'main' into schema-provider-resources
bendbennett Jun 19, 2023
9401282
Updating package names to match module name
bendbennett Jun 19, 2023
4d1a19c
Removing unneeded import from schema.gotmpl for data source, provider…
bendbennett Jun 20, 2023
daaddb3
Merge branch 'schema-provider-resources' into av/e2e-tests
austinvalle Jun 20, 2023
3c9346b
`make testdata`
austinvalle Jun 20, 2023
7b731af
import weirdness
austinvalle Jun 20, 2023
c08e6b4
use flagset to allow parallel tests to work
austinvalle Jun 20, 2023
d793ab7
add testdata
austinvalle Jun 20, 2023
53205c1
add complex test case
austinvalle Jun 20, 2023
1d004fb
Merge branch 'main' into av/e2e-tests
austinvalle Jun 21, 2023
9f747f1
revert IR json change
austinvalle Jun 21, 2023
ae591cc
move IR json
austinvalle Jun 21, 2023
4533b47
update example
austinvalle Jun 21, 2023
6e0318c
remove complex section as it was a duplicate
austinvalle Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ test:
generate:
cd tools; go generate ./...

# Regenerate testdata folder
testdata:
go run . all \
-input ./internal/cmd/testdata/custom_and_external/ir.json \
-output ./internal/cmd/testdata/custom_and_external/output

.PHONY: lint fmt test
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (a AllCommand) Synopsis() string {
func (a AllCommand) Run(args []string) int {
ctx := context.Background()
// parse flags
conf, err := config.New()
conf, err := config.New(args)
if err != nil {
log.Fatal(err)
}
Expand Down
95 changes: 95 additions & 0 deletions internal/cmd/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package cmd_test

import (
"os"
"path"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-codegen-framework/internal/cmd"
"github.com/mitchellh/cli"
)

func TestAllCommand(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
irInputPath string
goldenFileDir string
}{
"custom_and_external": {
irInputPath: "testdata/custom_and_external/ir.json",
goldenFileDir: "testdata/custom_and_external/output",
},
}
for name, testCase := range testCases {
name, testCase := name, testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

testOutputDir := t.TempDir()
mockUi := cli.NewMockUi()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. TIL there's a cli.NewMockUi().

c := cmd.AllCommand{Ui: mockUi}
args := []string{
"-input", testCase.irInputPath,
"-output", testOutputDir,
}

exitCode := c.Run(args)
if exitCode != 0 {
t.Fatalf("unexpected error running `all` cmd: %s", mockUi.ErrorWriter.String())
}

compareDirectories(t, testCase.goldenFileDir, testOutputDir)
})
}
}

// TODO: currently doesn't compare nested directory files
func compareDirectories(t *testing.T, wantDirPath, gotDirPath string) {
t.Helper()

wantDirEntries, err := os.ReadDir(wantDirPath)
if err != nil {
t.Fatalf("unexpected error reading `want` directory: %s", err)
}

gotDirEntries, err := os.ReadDir(gotDirPath)
if err != nil {
t.Fatalf("unexpected error reading `got` directory: %s", err)
}

if len(gotDirEntries) != len(wantDirEntries) {
t.Fatalf("mismatched files in output directory, wanted: %d file(s), got: %d file(s)", len(wantDirEntries), len(gotDirEntries))
}

for i, wantEntry := range wantDirEntries {
gotEntry := gotDirEntries[i]

if gotEntry.Name() != wantEntry.Name() {
t.Errorf("mismatched file name, wanted: %s, got: %s", wantEntry.Name(), gotEntry.Name())
continue
}

if gotEntry.Type() != wantEntry.Type() {
t.Errorf("mismatched file type, wanted: %s, got: %s", wantEntry.Type(), gotEntry.Type())
continue
}

gotFile, err := os.ReadFile(path.Join(gotDirPath, gotEntry.Name()))
if err != nil {
t.Fatalf("unexpected error reading `got` file: %s", err)
}
wantFile, _ := os.ReadFile(path.Join(wantDirPath, wantEntry.Name()))
if err != nil {
t.Fatalf("unexpected error reading `want` file: %s", err)
}

if diff := cmp.Diff(string(gotFile), string(wantFile)); diff != "" {
t.Errorf("unexpected difference in %s: %s", wantEntry.Name(), diff)
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be updated after hashicorp/terraform-plugin-codegen-spec#26 is merged

File renamed without changes.

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

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

Loading