Skip to content

Commit

Permalink
Merge pull request #39180 from acwwat/f-aws_synthetics_runtime_versio…
Browse files Browse the repository at this point in the history
…ns-new_data_source

feat: Add new aws_synthetics_runtime_verison and aws_synthetics_runtime_verisons data sources
  • Loading branch information
jar-b authored Sep 18, 2024
2 parents 3538f19 + 6d178c0 commit 9f19ad7
Show file tree
Hide file tree
Showing 12 changed files with 688 additions and 37 deletions.
6 changes: 6 additions & 0 deletions .changelog/39180.txt
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
```
51 changes: 51 additions & 0 deletions internal/framework/validators/bool_equals.go
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),
}
}
69 changes: 69 additions & 0 deletions internal/framework/validators/bool_equals_test.go
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)
}
})
}
}
Loading

0 comments on commit 9f19ad7

Please sign in to comment.