-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix nul pointer when datasource was not found
- Loading branch information
David MICHENEAU
committed
Nov 14, 2024
1 parent
ff904b0
commit 1d24b65
Showing
6 changed files
with
364 additions
and
276 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,73 @@ | ||
package testsacc | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/helpers/testsacc" | ||
) | ||
|
||
var _ testsacc.TestACC = &NATRuleDataSource{} | ||
|
||
const ( | ||
NATRuleDataSourceName = testsacc.ResourceName("data.cloudavenue_edgegateway_nat_rule") | ||
) | ||
|
||
const testAccNATRuleDataSourceConfig = ` | ||
data "cloudavenue_edgegateway_nat_rule" "example" { | ||
depends_on = [cloudavenue_edgegateway.example_with_vdc, cloudavenue_edgegateway_nat_rule.example] | ||
edge_gateway_id = cloudavenue_edgegateway.example_with_vdc.id | ||
name = "example-snat" | ||
type NATRuleDataSource struct{} | ||
|
||
func NewNATRuleDataSourceTest() testsacc.TestACC { | ||
return &NATRuleDataSource{} | ||
} | ||
` | ||
|
||
func TestAccNatRuleDataSource(t *testing.T) { | ||
dataSourceName := "data.cloudavenue_edgegateway_nat_rule.example" | ||
// GetResourceName returns the name of the resource. | ||
func (r *NATRuleDataSource) GetResourceName() string { | ||
return NATRuleDataSourceName.String() | ||
} | ||
|
||
func (r *NATRuleDataSource) DependenciesConfig() (resp testsacc.DependenciesConfigResponse) { | ||
resp.Append(GetResourceConfig()[NATRuleResourceName]().GetDefaultConfig) | ||
return | ||
} | ||
|
||
func (r *NATRuleDataSource) Tests(ctx context.Context) map[testsacc.TestName]func(ctx context.Context, resourceName string) testsacc.Test { | ||
return map[testsacc.TestName]func(ctx context.Context, resourceName string) testsacc.Test{ | ||
// * Test One (with edge_gateway_id) | ||
"example": func(_ context.Context, _ string) testsacc.Test { | ||
return testsacc.Test{ | ||
// ! Create testing | ||
Create: testsacc.TFConfig{ | ||
TFConfig: ` | ||
data "cloudavenue_edgegateway_nat_rule" "example" { | ||
edge_gateway_id = cloudavenue_edgegateway.example.id | ||
name = "example" | ||
}`, | ||
Checks: GetResourceConfig()[NATRuleResourceName]().GetDefaultChecks(), | ||
}, | ||
} | ||
}, | ||
// * Test Two (with edge_gateway_name) | ||
"example_2": func(_ context.Context, _ string) testsacc.Test { | ||
return testsacc.Test{ | ||
// ! Create testing | ||
Create: testsacc.TFConfig{ | ||
TFConfig: ` | ||
data "cloudavenue_edgegateway_nat_rule" "example" { | ||
edge_gateway_name = cloudavenue_edgegateway.example.name | ||
name = "example" | ||
}`, | ||
Checks: GetResourceConfig()[NATRuleResourceName]().GetDefaultChecks(), | ||
}, | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func TestAccNATRuleDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Read testing | ||
{ | ||
// Apply test | ||
Config: ConcatTests(testAccNATRuleResourceConfigSnat, testAccNATRuleDataSourceConfig, testAccEdgeGatewayResourceConfig), | ||
Check: natRuleSnatTestCheck(dataSourceName), | ||
}, | ||
}, | ||
Steps: testsacc.GenerateTests(&NATRuleDataSource{}), | ||
}) | ||
} |
Oops, something went wrong.