-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39180 from acwwat/f-aws_synthetics_runtime_versio…
…ns-new_data_source feat: Add new aws_synthetics_runtime_verison and aws_synthetics_runtime_verisons data sources
- Loading branch information
Showing
12 changed files
with
688 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```release-note:new-data-source | ||
aws_synthetics_runtime_version | ||
``` | ||
```release-note:new-data-source | ||
aws_synthetics_runtime_versions | ||
``` |
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,51 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package validators | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ validator.Bool = boolEqualsValidator{} | ||
|
||
type boolEqualsValidator struct { | ||
value types.Bool | ||
} | ||
|
||
func (v boolEqualsValidator) Description(ctx context.Context) string { | ||
return fmt.Sprintf("Value must be %q", v.value) | ||
} | ||
|
||
func (v boolEqualsValidator) MarkdownDescription(ctx context.Context) string { | ||
return v.Description(ctx) | ||
} | ||
|
||
func (v boolEqualsValidator) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) { | ||
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
configValue := req.ConfigValue | ||
|
||
if !configValue.Equal(v.value) { | ||
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( | ||
req.Path, | ||
v.Description(ctx), | ||
configValue.String(), | ||
)) | ||
} | ||
} | ||
|
||
// BoolEquals checks that the Bool held in the attribute matches the | ||
// given `value` | ||
func BoolEquals(value bool) validator.Bool { | ||
return boolEqualsValidator{ | ||
value: types.BoolValue(value), | ||
} | ||
} |
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,69 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package validators_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators" | ||
) | ||
|
||
func TestBoolEqualsValidator(t *testing.T) { | ||
t.Parallel() | ||
|
||
type testCase struct { | ||
in types.Bool | ||
validator validator.Bool | ||
expErrors int | ||
} | ||
|
||
testCases := map[string]testCase{ | ||
"simple-match": { | ||
in: types.BoolValue(true), | ||
validator: fwvalidators.BoolEquals(true), | ||
expErrors: 0, | ||
}, | ||
"simple-mismatch": { | ||
in: types.BoolValue(false), | ||
validator: fwvalidators.BoolEquals(true), | ||
expErrors: 1, | ||
}, | ||
"skip-validation-on-null": { | ||
in: types.BoolNull(), | ||
validator: fwvalidators.BoolEquals(true), | ||
expErrors: 0, | ||
}, | ||
"skip-validation-on-unknown": { | ||
in: types.BoolUnknown(), | ||
validator: fwvalidators.BoolEquals(true), | ||
expErrors: 0, | ||
}, | ||
} | ||
|
||
for name, test := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
req := validator.BoolRequest{ | ||
ConfigValue: test.in, | ||
} | ||
res := validator.BoolResponse{} | ||
test.validator.ValidateBool(context.TODO(), req, &res) | ||
|
||
if test.expErrors > 0 && !res.Diagnostics.HasError() { | ||
t.Fatalf("expected %d error(s), got none", test.expErrors) | ||
} | ||
|
||
if test.expErrors > 0 && test.expErrors != res.Diagnostics.ErrorsCount() { | ||
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, res.Diagnostics.ErrorsCount(), res.Diagnostics) | ||
} | ||
|
||
if test.expErrors == 0 && res.Diagnostics.HasError() { | ||
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.