MCPcopy Create free account
hub / github.com/crossplane-contrib/function-patch-and-transform / TestConvertResolve

Function TestConvertResolve

transforms_test.go:1105–1256  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1103}
1104
1105func TestConvertResolve(t *testing.T) {
1106 type args struct {
1107 to v1beta1.TransformIOType
1108 format *v1beta1.ConvertTransformFormat
1109 i any
1110 }
1111 type want struct {
1112 o any
1113 err error
1114 }
1115
1116 cases := map[string]struct {
1117 args
1118 want
1119 }{
1120 "StringToBool": {
1121 args: args{
1122 i: "true",
1123 to: v1beta1.TransformIOTypeBool,
1124 },
1125 want: want{
1126 o: true,
1127 },
1128 },
1129 "StringToFloat64": {
1130 args: args{
1131 i: "1000",
1132 to: v1beta1.TransformIOTypeFloat64,
1133 },
1134 want: want{
1135 o: 1000.0,
1136 },
1137 },
1138 "StringToQuantityFloat64": {
1139 args: args{
1140 i: "1000m",
1141 to: v1beta1.TransformIOTypeFloat64,
1142 format: (*v1beta1.ConvertTransformFormat)(ptr.To[string](string(v1beta1.ConvertTransformFormatQuantity))),
1143 },
1144 want: want{
1145 o: 1.0,
1146 },
1147 },
1148 "StringToQuantityFloat64InvalidFormat": {
1149 args: args{
1150 i: "1000 blabla",
1151 to: v1beta1.TransformIOTypeFloat64,
1152 format: (*v1beta1.ConvertTransformFormat)(ptr.To[string](string(v1beta1.ConvertTransformFormatQuantity))),
1153 },
1154 want: want{
1155 err: resource.ErrFormatWrong,
1156 },
1157 },
1158 "SameTypeNoOp": {
1159 args: args{
1160 i: true,
1161 to: v1beta1.TransformIOTypeBool,
1162 },

Callers

nothing calls this directly

Calls 3

TransformIOTypeTypeAlias · 0.92
ResolveConvertFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected