Skip to content

Commit

Permalink
Feat/improve integration test generation (#246)
Browse files Browse the repository at this point in the history
Co-authored-by: Sander Blue <sblue@sanderblue.com>
  • Loading branch information
noahmmcgivern and sanderblue committed May 23, 2024
1 parent 0a7dd4a commit a5b70a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ Flags for running the typegen command:
```bash
$ tutone fetch \
--config path/to/tutone.yaml \
--cache \
--output path/to/schema.json
--schema path/to/schema.json
```

3. Add a `./path/to/package/typegen.yaml` configuration with the type you want generated:
Expand Down
25 changes: 17 additions & 8 deletions templates/nerdgraphclient/integration_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@ import(
"github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers"
)

func Test{{$packageName | title}}(t *testing.T) {
{{range $index, $_ := .Mutations}}
func Test{{.Name | title}}(t *testing.T) {
t.Parallel()

t.Error("This test was generated but is incomplete. Please add the necessary code and additional test cases to cover the proper scenarios.")
client := new{{$packageName | title}}IntegrationTestClient(t)
require.NotNil(t, client)

// Add test cases below for CREATE, READ, UPDATE, and DELETE methods (if applicable).
// If your package includes any additional methods, please add integration tests for those as well.
{{range .Signature.Input -}}
{{.Name | untitle}} {{.Type}} := {{.Type}}{
// TODO: Add required variables to initialize instance of this input type
}
{{- end}}

result, err {{if (eq $index 0)}}:{{end}}= client.{{.Name | title}}(
{{- range .Signature.Input}}
{{.Name | untitle}},
{{- end}}
)

// BELOW IS ONLY AN EXAMPLE TEST FOR "CREATE". PLEASE UPDATE ACCORDINGLY
// result, err := client.AgentApplicationCreateBrowser(testAccountID, appName, settings)
// require.NoError(t, err)
// require.NotNil(t, result)
require.NoError(t, err)
require.NotNil(t, result)
}
{{end}}

func new{{$packageName | title}}IntegrationTestClient(t *testing.T) AgentApplications {
tc := testhelpers.NewIntegrationTestConfig(t)
Expand Down

0 comments on commit a5b70a6

Please sign in to comment.