Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_evidently_feature #27395

Merged
merged 30 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a7238b7
feat(nullable): type nullable float
GlennChia Oct 21, 2022
9302cc9
test(nullable): type nullable float
GlennChia Oct 21, 2022
bdef634
feat(cwevi): feature schema
GlennChia Oct 21, 2022
41febff
feat(cwevi): feature read
GlennChia Oct 21, 2022
7d5df83
feat(cwevi): feature create
GlennChia Oct 21, 2022
3c7d0a6
feat(cwevi): feature update
GlennChia Oct 22, 2022
b815bd1
feat(cwevi): feature delete
GlennChia Oct 22, 2022
0a472b5
feat(cwevi): aws_evidently_feature provider
GlennChia Oct 22, 2022
73a4aaa
test(cwevi): feature basic
GlennChia Oct 22, 2022
a2f52f5
test(cwevi): feature disappears
GlennChia Oct 22, 2022
25af78e
test(cwevi): feature tags
GlennChia Oct 22, 2022
b8efc7f
test(cwevi): feature update default_variation
GlennChia Oct 22, 2022
872fb02
test(cwevi): feature update description
GlennChia Oct 22, 2022
9bf5d06
test(cwevi): feature update entity_overrides
GlennChia Oct 22, 2022
ab498d3
test(cwevi): feature update evaluation_strategy
GlennChia Oct 22, 2022
c045306
test(cwevi): feature update variations bool_value
GlennChia Oct 22, 2022
574ed11
test(cwevi): feature update variation double_value
GlennChia Oct 22, 2022
6fb4812
test(cwevi): feature update variation long_value
GlennChia Oct 22, 2022
68ce44b
test(cwevi): feature update variation string_value
GlennChia Oct 22, 2022
ed32809
refactor(cwevi): waiters use WaitForStateContext
GlennChia Oct 22, 2022
ca5b57a
feat(cwevi): feature waiter for create
GlennChia Oct 22, 2022
edabdea
feat(cwevi): feature waiter for update
GlennChia Oct 22, 2022
9ed0cab
feat(cwevi): feature waiter for delete
GlennChia Oct 22, 2022
8500ef8
docs(cwevi): aws_evidently_feature
GlennChia Oct 22, 2022
505acf5
feat(cwevi): set arn in id and schema
GlennChia Oct 22, 2022
65434f7
ci(cwevi): changelog aws_evidently_feature
GlennChia Oct 22, 2022
7a72722
refactor(cwevi): feature comment long_value valid
GlennChia Oct 23, 2022
12612fd
refactor(cwevi): rm unnecessary conversion
GlennChia Oct 23, 2022
3dda000
ci(cwevi): exporting a pointer for loop variable k
GlennChia Oct 23, 2022
0ff3f57
Merge branch 'main' into HEAD
ewbankkit Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/27395.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_evidently_feature
```
50 changes: 50 additions & 0 deletions internal/experimental/nullable/float.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package nullable

import (
"fmt"
"strconv"

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

const (
TypeNullableFloat = schema.TypeString
)

type Float string

func (i Float) IsNull() bool {
return i == ""
}

func (i Float) Value() (float64, bool, error) {
if i.IsNull() {
return 0, true, nil
}

value, err := strconv.ParseFloat(string(i), 64)
if err != nil {
return 0, false, err
}
return value, false, nil
}

// ValidateTypeStringNullableFloat provides custom error messaging for TypeString floats
// Some arguments require an float value or unspecified, empty field.
func ValidateTypeStringNullableFloat(v interface{}, k string) (ws []string, es []error) {
value, ok := v.(string)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be string", k))
return
}

if value == "" {
return
}

if _, err := strconv.ParseFloat(value, 64); err != nil {
es = append(es, fmt.Errorf("%s: cannot parse '%s' as float: %w", k, value, err))
}

return
}
95 changes: 95 additions & 0 deletions internal/experimental/nullable/float_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package nullable

import (
"errors"
"regexp"
"strconv"
"testing"
)

func TestNullableFloat(t *testing.T) {
cases := []struct {
val string
expectNull bool
expectedValue float64
expectedErr error
}{
{
val: "1",
expectNull: false,
expectedValue: 1,
},
{
val: "1.1",
expectNull: false,
expectedValue: 1.1,
},
{
val: "0",
expectNull: false,
expectedValue: 0,
},
{
val: "",
expectNull: true,
expectedValue: 0,
},
{
val: "A",
expectNull: false,
expectedValue: 0,
expectedErr: strconv.ErrSyntax,
},
}

for i, tc := range cases {
v := Float(tc.val)

if null := v.IsNull(); null != tc.expectNull {
t.Fatalf("expected test case %d IsNull to return %t, got %t", i, null, tc.expectNull)
}

value, null, err := v.Value()
if value != tc.expectedValue {
t.Fatalf("expected test case %d Value to be %f, got %f", i, tc.expectedValue, value)
}
if null != tc.expectNull {
t.Fatalf("expected test case %d Value null flag to be %t, got %t", i, tc.expectNull, null)
}
if tc.expectedErr == nil && err != nil {
t.Fatalf("expected test case %d to succeed, got error %s", i, err)
}
if tc.expectedErr != nil {
if !errors.Is(err, tc.expectedErr) {
t.Fatalf("expected test case %d to have error matching \"%s\", got %s", i, tc.expectedErr, err)
}
}
}
}

func TestValidationFloat(t *testing.T) {
runTestCases(t, []testCase{
{
val: "1",
f: ValidateTypeStringNullableFloat,
},
{
val: "1.1",
f: ValidateTypeStringNullableFloat,
},
{
val: "0",
f: ValidateTypeStringNullableFloat,
},
{
val: "A",
f: ValidateTypeStringNullableFloat,
expectedErr: regexp.MustCompile(`[\w]+: cannot parse 'A' as float: .*`),
},
{
val: 1,
f: ValidateTypeStringNullableFloat,
expectedErr: regexp.MustCompile(`expected type of [\w]+ to be string`),
},
})
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ func New(_ context.Context) (*schema.Provider, error) {

"aws_emrserverless_application": emrserverless.ResourceApplication(),

"aws_evidently_feature": evidently.ResourceFeature(),
"aws_evidently_project": evidently.ResourceProject(),
"aws_evidently_segment": evidently.ResourceSegment(),

Expand Down
Loading