Skip to content

Commit

Permalink
feat: new template definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
eremid committed Feb 28, 2023
1 parent 1bea6ee commit 5e628cc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions templates/acc_test_datasource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

tests "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/tests/common"
)

//go:generate go run github.com/FrangipaneTeam/tf-doc-extractor@latest -filename $GOFILE -example-dir ../../examples -test
//go:generate go run github.com/FrangipaneTeam/tf-doc-extractor@latest -filename $GOFILE -example-dir ../../../examples -test
const testAcc{{ .CamelName }}DataSourceConfig = `
data "cloudavenue_{{ .Name }}" "example" {
}
Expand All @@ -16,8 +18,8 @@ const dataSourceName = "data.cloudavenue_{{ .Name }}.example"

func TestAcc{{ .CamelName }}DataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: func() { tests.TestAccPreCheck(t) },
ProtoV6ProviderFactories: tests.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
Expand Down
10 changes: 6 additions & 4 deletions templates/acc_test_resource.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package tests
package {{ .PackageName }}

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

tests "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/tests/common"
)

//go:generate go run github.com/FrangipaneTeam/tf-doc-extractor@latest -filename $GOFILE -example-dir ../../examples -test
//go:generate go run github.com/FrangipaneTeam/tf-doc-extractor@latest -filename $GOFILE -example-dir ../../../examples -test
const testAcc{{ .CamelName }}ResourceConfig = `
resource "cloudavenue_{{ .Name }}" "example" {
}
Expand All @@ -16,8 +18,8 @@ const resourceName = "cloudavenue_{{ .Name }}.example"

func TestAcc{{ .CamelName }}Resource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: func() { tests.TestAccPreCheck(t) },
ProtoV6ProviderFactories: tests.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
Expand Down
2 changes: 1 addition & 1 deletion templates/datasource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type {{ .LowerCamelName }}DataSourceModel struct {
}

func (d *{{ .LowerCamelName }}DataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + "{{ .Name }}"
resp.TypeName = req.ProviderTypeName + "_" + categoryName + "_{{ .Name }}"
}

func (d *{{ .LowerCamelName }}DataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
Expand Down
3 changes: 2 additions & 1 deletion templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type {{ .LowerCamelName }}ResourceModel struct {

// Metadata returns the resource type name.
func (r *{{ .LowerCamelName }}Resource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "{{ .Name }}"
resp.TypeName = req.ProviderTypeName + "_" + categoryName + "_{{ .Name }}"
}

// Schema defines the schema for the resource.
Expand Down Expand Up @@ -137,6 +137,7 @@ func (r *{{ .LowerCamelName }}Resource) Delete(ctx context.Context, req resource
}
}

//go:generate go run github.com/FrangipaneTeam/tf-doc-extractor@latest -filename $GOFILE -example-dir ../../../examples -resource
func (r *{{ .LowerCamelName }}Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

0 comments on commit 5e628cc

Please sign in to comment.