-
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.
- Loading branch information
Showing
38 changed files
with
3,276 additions
and
4 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
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
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,107 @@ | ||
// Code generated by Polytomic. DO NOT EDIT. | ||
// edit connections.yaml and re-run go generate | ||
|
||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAcc{{ .Connection }}Connection(t *testing.T) { | ||
name := "TestAcc" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Missing configuration | ||
{ | ||
Config: testAcc{{ .Connection }}ConnectionResourceNoConfig(name), | ||
ExpectError: regexp.MustCompile("The argument \"configuration\" is required, but no definition was found."), | ||
}, | ||
// Empty configuration | ||
{ | ||
Config: testAcc{{ .Connection }}ConnectionResourceMissingRequired(name), | ||
ExpectError: regexp.MustCompile("Inappropriate value for attribute \"configuration\":"), | ||
}, | ||
{ | ||
Config: testAcc{{ .Connection }}ConnectionResource(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
// Check if the resource exists | ||
testAcc{{ .Connection }}ConnectionExists(name), | ||
// Check the name | ||
resource.TestCheckResourceAttr("polytomic_{{ .ResourceName }}_connection.test", "name", name), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAcc{{ .Connection }}ConnectionExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
_, ok := s.RootModule().Resources["polytomic_{{ .ResourceName }}_connection.test"] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", "polytomic_{{ .ResourceName }}_connection.test") | ||
} | ||
|
||
client := testClient() | ||
connections, err := client.Connections().List(context.TODO()) | ||
if err != nil { | ||
return err | ||
} | ||
var found bool | ||
for _, connection := range connections { | ||
if connection.Name == name { | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found { | ||
return fmt.Errorf("connection %s not found", name) | ||
} | ||
|
||
return nil | ||
|
||
} | ||
} | ||
|
||
func testAcc{{ .Connection }}ConnectionResource(name string) string { | ||
return fmt.Sprintf(` | ||
resource "polytomic_{{ .ResourceName }}_connection" "test" { | ||
name = "%s" | ||
configuration = { | ||
{{- range .Attributes }} | ||
{{- if .Example }} | ||
{{- if eq .Type "string" }} | ||
{{ .AttrName }} = "{{ .Example }}" | ||
{{- else }} | ||
{{ .AttrName }} = {{ .Example }} | ||
{{- end -}} | ||
{{ end }} | ||
{{- end }} | ||
} | ||
} | ||
`, name) | ||
} | ||
|
||
func testAcc{{ .Connection }}ConnectionResourceNoConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "polytomic_{{ .ResourceName }}_connection" "test" { | ||
name = "%s" | ||
} | ||
`, name) | ||
} | ||
|
||
func testAcc{{ .Connection }}ConnectionResourceMissingRequired(name string) string { | ||
return fmt.Sprintf(` | ||
resource "polytomic_{{ .ResourceName }}_connection" "test" { | ||
name = "%s" | ||
configuration = {} | ||
}`, name) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.