Skip to content

Commit 5ef1ee5

Browse files
committed
Add many uppercase test attribute
1 parent 7cb1d3a commit 5ef1ee5

File tree

3 files changed

+69
-37
lines changed

3 files changed

+69
-37
lines changed

internal/common/autogen/marshal_test.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestMarshalBasic(t *testing.T) {
5656
AttrBoolTrue types.Bool `tfsdk:"attr_bool_true"`
5757
AttrBoolFalse types.Bool `tfsdk:"attr_bool_false"`
5858
AttrBoolNull types.Bool `tfsdk:"attr_bool_null"`
59+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
5960
}{
6061
AttrFloat: types.Float64Value(1.234),
6162
AttrString: types.StringValue("hello"),
@@ -68,8 +69,19 @@ func TestMarshalBasic(t *testing.T) {
6869
AttrBoolFalse: types.BoolValue(false),
6970
AttrBoolNull: types.BoolNull(), // null values are not marshaled
7071
AttrJSON: jsontypes.NewNormalizedValue("{\"hello\": \"there\"}"),
72+
AttrMANYUpper: types.Int64Value(2),
7173
}
72-
const expectedJSON = `{ "attrString": "hello", "attrInt": 1, "attrFloat": 1.234, "attrBoolTrue": true, "attrBoolFalse": false, "attrJSON": {"hello": "there"} }`
74+
const expectedJSON = `
75+
{
76+
"attrString": "hello",
77+
"attrInt": 1,
78+
"attrFloat": 1.234,
79+
"attrBoolTrue": true,
80+
"attrBoolFalse": false,
81+
"attrJSON": {"hello": "there"},
82+
"attrMANYUpper": 2
83+
}
84+
`
7385
raw, err := autogen.Marshal(&model, false)
7486
require.NoError(t, err)
7587
assert.JSONEq(t, expectedJSON, string(raw))
@@ -295,6 +307,7 @@ func TestMarshalCustomTypeObject(t *testing.T) {
295307
AttrObjectOmitUpdate customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_object_omit_update" autogen:"omitjsonupdate"`
296308
AttrNull customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_null" autogen:"includenullonupdate"`
297309
AttrInt types.Int64 `tfsdk:"attr_int"`
310+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
298311
}
299312

300313
type modelCustomTypeParentTest struct {
@@ -316,6 +329,7 @@ func TestMarshalCustomTypeObject(t *testing.T) {
316329
AttrObjectOmit: emptyObject,
317330
AttrObjectOmitUpdate: emptyObject,
318331
AttrNull: nullObject,
332+
AttrMANYUpper: types.Int64Value(2),
319333
}),
320334
AttrObjectNull: customtype.NewObjectValueNull[modelCustomTypeTest](ctx),
321335
AttrObjectNested: customtype.NewObjectValue[modelCustomTypeParentTest](ctx, modelCustomTypeParentTest{
@@ -326,6 +340,7 @@ func TestMarshalCustomTypeObject(t *testing.T) {
326340
AttrObjectOmit: emptyObject,
327341
AttrObjectOmitUpdate: emptyObject,
328342
AttrNull: nullObject,
343+
AttrMANYUpper: types.Int64Value(3),
329344
}),
330345
}),
331346
}
@@ -334,12 +349,14 @@ func TestMarshalCustomTypeObject(t *testing.T) {
334349
{
335350
"attrObjectBasic": {
336351
"attrInt": 1,
337-
"attrObjectOmitUpdate": {}
352+
"attrObjectOmitUpdate": {},
353+
"attrMANYUpper": 2
338354
},
339355
"attrObjectNested": {
340356
"attrObject": {
341357
"attrInt": 2,
342-
"attrObjectOmitUpdate": {}
358+
"attrObjectOmitUpdate": {},
359+
"attrMANYUpper": 3
343360
},
344361
"attrString": "parent"
345362
}
@@ -353,12 +370,14 @@ func TestMarshalCustomTypeObject(t *testing.T) {
353370
{
354371
"attrObjectBasic": {
355372
"attrInt": 1,
356-
"attrNull": null
373+
"attrNull": null,
374+
"attrMANYUpper": 2
357375
},
358376
"attrObjectNested": {
359377
"attrObject": {
360378
"attrInt": 2,
361-
"attrNull": null
379+
"attrNull": null,
380+
"attrMANYUpper": 3
362381
},
363382
"attrString": "parent"
364383
}

internal/common/autogen/unknown_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestResolveUnknowns(t *testing.T) {
2020
type modelCustomTypeTest struct {
2121
AttrKnownString types.String `tfsdk:"attr_known_string"`
2222
AttrUnknownObject customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_unknown_object"`
23+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
2324
}
2425

2526
type modelst struct {
@@ -83,6 +84,7 @@ func TestResolveUnknowns(t *testing.T) {
8384
AttrCustomObject: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
8485
AttrKnownString: types.StringValue("val1"),
8586
AttrUnknownObject: customtype.NewObjectValueUnknown[modelEmptyTest](ctx),
87+
AttrMANYUpper: types.Int64Unknown(),
8688
}),
8789
}
8890
modelExpected := modelst{
@@ -133,6 +135,7 @@ func TestResolveUnknowns(t *testing.T) {
133135
AttrCustomObject: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
134136
AttrKnownString: types.StringValue("val1"),
135137
AttrUnknownObject: customtype.NewObjectValueNull[modelEmptyTest](ctx),
138+
AttrMANYUpper: types.Int64Null(),
136139
}),
137140
}
138141
require.NoError(t, autogen.ResolveUnknowns(&model))

internal/common/autogen/unmarshal_test.go

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestUnmarshalBasic(t *testing.T) {
2424
AttrIntWithFloat types.Int64 `tfsdk:"attr_int_with_float"`
2525
AttrTrue types.Bool `tfsdk:"attr_true"`
2626
AttrFalse types.Bool `tfsdk:"attr_false"`
27+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
2728
}
2829
const (
2930
// attribute_not_in_model is ignored because it is not in the model, no error is thrown.
@@ -39,7 +40,8 @@ func TestUnmarshalBasic(t *testing.T) {
3940
"attrFloatWithInt": 13,
4041
"attrNotInModel": "val",
4142
"attrNull": null,
42-
"attrJSON": {"hello": "there"}
43+
"attrJSON": {"hello": "there"},
44+
"attrMANYUpper": 1
4345
}
4446
`
4547
)
@@ -52,6 +54,7 @@ func TestUnmarshalBasic(t *testing.T) {
5254
assert.InEpsilon(t, float64(456.1), model.AttrFloat.ValueFloat64(), epsilon)
5355
assert.InEpsilon(t, float64(13), model.AttrFloatWithInt.ValueFloat64(), epsilon)
5456
assert.True(t, model.AttrNotInJSON.IsNull()) // attributes not in JSON response are not changed, so null is kept.
57+
assert.Equal(t, int64(1), model.AttrMANYUpper.ValueInt64())
5558
assert.JSONEq(t, "{\"hello\":\"there\"}", model.AttrJSON.ValueString())
5659
}
5760

@@ -62,11 +65,12 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
6265
type modelEmptyTest struct{}
6366

6467
type modelCustomTypeTest struct {
65-
AttrFloat types.Float64 `tfsdk:"attr_float"`
66-
AttrString types.String `tfsdk:"attr_string"`
67-
AttrNested customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_nested"`
68-
AttrInt types.Int64 `tfsdk:"attr_int"`
69-
AttrBool types.Bool `tfsdk:"attr_bool"`
68+
AttrFloat types.Float64 `tfsdk:"attr_float"`
69+
AttrString types.String `tfsdk:"attr_string"`
70+
AttrNested customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_nested"`
71+
AttrInt types.Int64 `tfsdk:"attr_int"`
72+
AttrBool types.Bool `tfsdk:"attr_bool"`
73+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
7074
}
7175

7276
type modelst struct {
@@ -109,11 +113,12 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
109113
AttrObjParent: types.ObjectNull(objTypeParentTest.AttrTypes),
110114
AttrCustomObj: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
111115
// these attribute values are irrelevant, they will be overwritten with JSON values
112-
AttrString: types.StringValue("different_string"),
113-
AttrInt: types.Int64Value(999),
114-
AttrFloat: types.Float64Unknown(), // can even be unknown
115-
AttrBool: types.BoolUnknown(), // can even be unknown
116-
AttrNested: customtype.NewObjectValueUnknown[modelEmptyTest](ctx),
116+
AttrString: types.StringValue("different_string"),
117+
AttrInt: types.Int64Value(999),
118+
AttrFloat: types.Float64Unknown(), // can even be unknown
119+
AttrBool: types.BoolUnknown(), // can even be unknown
120+
AttrNested: customtype.NewObjectValueUnknown[modelEmptyTest](ctx),
121+
AttrMANYUpper: types.Int64Value(999),
117122
}),
118123
AttrCustomObjNullNotSent: customtype.NewObjectValueNull[modelCustomTypeTest](ctx),
119124
AttrCustomObjNullSent: customtype.NewObjectValueNull[modelCustomTypeTest](ctx),
@@ -172,7 +177,8 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
172177
"attrInt": 123,
173178
"attrFloat": 1.1,
174179
"attrBool": true,
175-
"attrNested": {}
180+
"attrNested": {},
181+
"attrMANYUpper": 456
176182
},
177183
"attrCustomObjNullSent": {
178184
"attrString": "null_obj",
@@ -325,34 +331,38 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
325331
}),
326332
}),
327333
AttrCustomObj: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
328-
AttrString: types.StringValue("value_string"),
329-
AttrInt: types.Int64Value(123),
330-
AttrFloat: types.Float64Value(1.1),
331-
AttrBool: types.BoolValue(true),
332-
AttrNested: customtype.NewObjectValue[modelEmptyTest](ctx, modelEmptyTest{}),
334+
AttrString: types.StringValue("value_string"),
335+
AttrInt: types.Int64Value(123),
336+
AttrFloat: types.Float64Value(1.1),
337+
AttrBool: types.BoolValue(true),
338+
AttrNested: customtype.NewObjectValue[modelEmptyTest](ctx, modelEmptyTest{}),
339+
AttrMANYUpper: types.Int64Value(456),
333340
}),
334341
AttrCustomObjNullNotSent: customtype.NewObjectValueNull[modelCustomTypeTest](ctx),
335342
AttrCustomObjNullSent: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
336-
AttrString: types.StringValue("null_obj"),
337-
AttrInt: types.Int64Value(1),
338-
AttrFloat: types.Float64Null(),
339-
AttrBool: types.BoolNull(),
340-
AttrNested: customtype.NewObjectValueNull[modelEmptyTest](ctx),
343+
AttrString: types.StringValue("null_obj"),
344+
AttrInt: types.Int64Value(1),
345+
AttrFloat: types.Float64Null(),
346+
AttrBool: types.BoolNull(),
347+
AttrNested: customtype.NewObjectValueNull[modelEmptyTest](ctx),
348+
AttrMANYUpper: types.Int64Null(),
341349
}),
342350
AttrCustomObjUnknownNotSent: customtype.NewObjectValueUnknown[modelCustomTypeTest](ctx),
343351
AttrCustomObjUnknownSent: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
344-
AttrString: types.StringValue("unknown_obj"),
345-
AttrInt: types.Int64Null(),
346-
AttrFloat: types.Float64Null(),
347-
AttrBool: types.BoolNull(),
348-
AttrNested: customtype.NewObjectValueNull[modelEmptyTest](ctx),
352+
AttrString: types.StringValue("unknown_obj"),
353+
AttrInt: types.Int64Null(),
354+
AttrFloat: types.Float64Null(),
355+
AttrBool: types.BoolNull(),
356+
AttrNested: customtype.NewObjectValueNull[modelEmptyTest](ctx),
357+
AttrMANYUpper: types.Int64Null(),
349358
}),
350359
AttrCustomObjParent: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
351-
AttrString: types.StringValue("parent string"),
352-
AttrInt: types.Int64Null(),
353-
AttrFloat: types.Float64Null(),
354-
AttrBool: types.BoolNull(),
355-
AttrNested: customtype.NewObjectValue[modelEmptyTest](ctx, modelEmptyTest{}),
360+
AttrString: types.StringValue("parent string"),
361+
AttrInt: types.Int64Null(),
362+
AttrFloat: types.Float64Null(),
363+
AttrBool: types.BoolNull(),
364+
AttrNested: customtype.NewObjectValue[modelEmptyTest](ctx, modelEmptyTest{}),
365+
AttrMANYUpper: types.Int64Null(),
356366
}),
357367
AttrListString: types.ListValueMust(types.StringType, []attr.Value{
358368
types.StringValue("list1"),

0 commit comments

Comments
 (0)