1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
|
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ext
import (
"fmt"
"reflect"
"sort"
"strings"
"testing"
"time"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"github.com/google/cel-go/cel"
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/pb"
"github.com/google/cel-go/common/types/ref"
"github.com/google/cel-go/common/types/traits"
"github.com/google/cel-go/test"
proto3pb "github.com/google/cel-go/test/proto3pb"
structpb "google.golang.org/protobuf/types/known/structpb"
)
func TestNativeTypes(t *testing.T) {
var nativeTests = []struct {
expr string
out any
in any
}{
{
expr: `ext.TestAllTypes{
NestedVal: ext.TestNestedType{NestedMapVal: {1: false}},
BoolVal: true,
BytesVal: b'hello',
DurationVal: duration('5s'),
DoubleVal: 1.5,
FloatVal: 2.5,
Int32Val: 10,
Int64Val: 20,
StringVal: 'hello world',
TimestampVal: timestamp('2011-08-06T01:23:45Z'),
Uint32Val: 100u,
Uint64Val: 200u,
ListVal: [
ext.TestNestedType{
NestedListVal:['goodbye', 'cruel', 'world'],
NestedMapVal: {42: true},
},
],
MapVal: {'map-key': ext.TestAllTypes{BoolVal: true}},
}`,
out: &TestAllTypes{
NestedVal: &TestNestedType{NestedMapVal: map[int64]bool{1: false}},
BoolVal: true,
BytesVal: []byte("hello"),
DurationVal: time.Second * 5,
DoubleVal: 1.5,
FloatVal: 2.5,
Int32Val: 10,
Int64Val: 20,
StringVal: "hello world",
TimestampVal: mustParseTime(t, "2011-08-06T01:23:45Z"),
Uint32Val: uint32(100),
Uint64Val: uint64(200),
ListVal: []*TestNestedType{
{
NestedListVal: []string{"goodbye", "cruel", "world"},
NestedMapVal: map[int64]bool{42: true},
},
},
MapVal: map[string]TestAllTypes{"map-key": {BoolVal: true}},
},
},
{
expr: `ext.TestAllTypes{
PbVal: test.TestAllTypes{single_int32: 123}
}.PbVal`,
out: &proto3pb.TestAllTypes{SingleInt32: 123},
},
{
expr: `ext.TestAllTypes{PbVal: test.TestAllTypes{}} ==
ext.TestAllTypes{PbVal: test.TestAllTypes{single_bool: false}}`,
},
{expr: `ext.TestNestedType{} == TestNestedType{}`},
{expr: `ext.TestAllTypes{}.BoolVal != true`},
{expr: `!has(ext.TestAllTypes{}.BoolVal) && !has(ext.TestAllTypes{}.NestedVal)`},
{expr: `type(ext.TestAllTypes) == type`},
{expr: `type(ext.TestAllTypes{}) == ext.TestAllTypes`},
{expr: `type(ext.TestAllTypes{}) == ext.TestAllTypes`},
{expr: `ext.TestAllTypes != test.TestAllTypes`},
{expr: `ext.TestAllTypes{BoolVal: true} != dyn(test.TestAllTypes{single_bool: true})`},
{expr: `ext.TestAllTypes{}.NestedVal == ext.TestNestedType{}`},
{expr: `ext.TestNestedType{} == ext.TestAllTypes{}.NestedStructVal`},
{expr: `ext.TestAllTypes{}.NestedStructVal == ext.TestNestedType{}`},
{expr: `ext.TestAllTypes{}.ListVal.size() == 0`},
{expr: `ext.TestAllTypes{}.MapVal.size() == 0`},
{expr: `ext.TestAllTypes{}.TimestampVal == timestamp(0)`},
{expr: `test.TestAllTypes{}.single_timestamp == timestamp(0)`},
{expr: `[TestAllTypes{BoolVal: true}, TestAllTypes{BoolVal: false}].exists(t, t.BoolVal == true)`},
{
expr: `tests.all(t, t.Int32Val > 17)`,
in: map[string]any{
"tests": []*TestAllTypes{{Int32Val: 18}, {Int32Val: 19}, {Int32Val: 20}},
},
},
}
env := testNativeEnv(t)
for i, tst := range nativeTests {
tc := tst
t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) {
var asts []*cel.Ast
pAst, iss := env.Parse(tc.expr)
if iss.Err() != nil {
t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err())
}
asts = append(asts, pAst)
cAst, iss := env.Check(pAst)
if iss.Err() != nil {
t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err())
}
asts = append(asts, cAst)
for _, ast := range asts {
prg, err := env.Program(ast)
if err != nil {
t.Fatal(err)
}
in := tc.in
if in == nil {
in = cel.NoVars()
}
out, _, err := prg.Eval(in)
if err != nil {
t.Fatal(err)
}
want := tc.out
if want == nil {
want = true
}
wantPB, isPB := want.(proto.Message)
if isPB && !pb.Equal(wantPB, out.Value().(proto.Message)) {
t.Errorf("got %v, wanted %v for expr: %s", out.Value(), want, tc.expr)
}
if !isPB && !reflect.DeepEqual(out.Value(), want) {
t.Errorf("got %v, wanted %v for expr: %s", out.Value(), want, tc.expr)
}
}
})
}
}
func TestNativeFindStructFieldNames(t *testing.T) {
env := testNativeEnv(t)
provider := env.CELTypeProvider()
tests := []struct {
typeName string
fields []string
}{
{
typeName: "ext.TestNestedType",
fields: []string{"NestedListVal", "NestedMapVal"},
},
{
typeName: "google.expr.proto3.test.TestAllTypes.NestedMessage",
fields: []string{"bb"},
},
{
typeName: "invalid.TypeName",
fields: []string{},
},
}
for _, tst := range tests {
tc := tst
t.Run(fmt.Sprintf("%s", tc.typeName), func(t *testing.T) {
fields, _ := provider.FindStructFieldNames(tc.typeName)
sort.Strings(fields)
sort.Strings(tc.fields)
if !reflect.DeepEqual(fields, tc.fields) {
t.Errorf("got %v, wanted %v", fields, tc.fields)
}
})
}
}
func TestNativeTypesStaticErrors(t *testing.T) {
var nativeTests = []struct {
expr string
err string
}{
{
expr: `TestAllTypos{}`,
err: `ERROR: <input>:1:13: undeclared reference to 'TestAllTypos' (in container 'ext')
| TestAllTypos{}
| ............^`,
},
{
expr: `ext.TestAllTypes{bool_val: false}`,
err: `ERROR: <input>:1:26: undefined field 'bool_val'
| ext.TestAllTypes{bool_val: false}
| .........................^`,
},
{
expr: `ext.TestAllTypes{UnsupportedVal: null}`,
err: `ERROR: <input>:1:32: undefined field 'UnsupportedVal'
| ext.TestAllTypes{UnsupportedVal: null}
| ...............................^`,
},
{
expr: `ext.TestAllTypes{UnsupportedListVal: null}`,
err: `ERROR: <input>:1:36: undefined field 'UnsupportedListVal'
| ext.TestAllTypes{UnsupportedListVal: null}
| ...................................^`,
},
{
expr: `ext.TestAllTypes{UnsupportedMapVal: null}`,
err: `ERROR: <input>:1:35: undefined field 'UnsupportedMapVal'
| ext.TestAllTypes{UnsupportedMapVal: null}
| ..................................^`,
},
}
env := testNativeEnv(t)
for i, tst := range nativeTests {
tc := tst
t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) {
_, iss := env.Compile(tc.expr)
if iss.Err() == nil {
t.Fatalf("env.Compile(%v) succeeded, wanted error", tc.expr)
}
if !test.Compare(iss.Err().Error(), tc.err) {
t.Errorf("env.Compile(%v) got %v, wanted error %s", tc.expr, iss.Err(), tc.err)
}
})
}
}
func TestNativeTypesJsonSerialization(t *testing.T) {
tests := []struct {
expr string
out string
}{
{
expr: `[b'string']`,
out: `["c3RyaW5n"]`,
},
{
expr: `TestAllTypes{
BoolVal: true,
DurationVal: duration('5s'),
DoubleVal: 1.5,
FloatVal: 2.0,
Int32Val: 23,
Int64Val: 64,
MapVal: {
'map-key': ext.TestAllTypes{
BoolVal: true
}
},
NestedVal: TestNestedType{
NestedListVal: ["first", "second"],
},
StringVal: "string"
}`,
out: `{
"BoolVal": true,
"DoubleVal": 1.5,
"DurationVal": "5s",
"FloatVal": 2,
"Int32Val": 23,
"Int64Val": 64,
"MapVal": {
"map-key": {
"BoolVal": true
}
},
"NestedVal": {
"NestedListVal": [
"first",
"second"
]
},
"StringVal": "string"
}`,
},
}
env := testNativeEnv(t)
for i, tst := range tests {
tc := tst
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
ast, iss := env.Compile(tc.expr)
if iss.Err() != nil {
t.Fatalf("env.Compile(%v) failed: %v", tc.expr, iss.Err())
}
prg, err := env.Program(ast)
if err != nil {
t.Fatalf("env.Program() failed: %v", err)
}
out, _, err := prg.Eval(cel.NoVars())
if err != nil {
t.Fatalf("prg.Eval() failed: %v", err)
}
conv, err := out.ConvertToNative(reflect.TypeOf(&structpb.Value{}))
if err != nil {
t.Fatalf("out.ConvertToNative(Value) failed: %v", err)
}
json := protojson.Format(conv.(proto.Message))
if !test.Compare(json, tc.out) {
t.Errorf("expr %v converted to %v, wanted %v", tc.expr, json, tc.out)
}
})
}
}
func TestNativeTypesRuntimeErrors(t *testing.T) {
var nativeTests = []struct {
expr string
err string
}{
{
expr: `TestAllTypos{}`,
err: `unknown type: TestAllTypos`,
},
{
expr: `ext.TestAllTypes{bool_val: false}`,
err: `no such field: bool_val`,
},
{
expr: `ext.TestAllTypes{UnsupportedVal: null}`,
err: `no such field: UnsupportedVal`,
},
{
expr: `ext.TestAllTypes{UnsupportedListVal: null}`,
err: `no such field: UnsupportedListVal`,
},
{
expr: `ext.TestAllTypes{UnsupportedMapVal: null}`,
err: `no such field: UnsupportedMapVal`,
},
{
expr: `ext.TestAllTypes{privateVal: null}`,
err: `no such field: privateVal`,
},
{
expr: `ext.TestAllTypes{}.UnsupportedMapVal`,
err: `no such field: UnsupportedMapVal`,
},
{
expr: `ext.TestAllTypes{}.privateVal`,
err: `no such field: privateVal`,
},
{
expr: `ext.TestAllTypes{BoolVal: 'false'}`,
err: `unsupported native conversion from string to 'bool'`,
},
{
expr: `has(ext.TestAllTypes{}.BadFieldName)`,
err: `no such field: BadFieldName`,
},
{
expr: `ext.TestAllTypes{}[42]`,
err: `no such overload`,
},
{
expr: `ext.TestAllTypes{Int32Val: 9223372036854775807}`,
err: `integer overflow`,
},
{
expr: `ext.TestAllTypes{Uint32Val: 9223372036854775807u}`,
err: `unsigned integer overflow`,
},
}
env := testNativeEnv(t)
for i, tst := range nativeTests {
tc := tst
t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) {
ast, iss := env.Parse(tc.expr)
if iss.Err() != nil {
t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err())
}
prg, err := env.Program(ast)
if err != nil {
if !strings.Contains(err.Error(), tc.err) {
t.Fatal(err)
}
return
}
out, _, err := prg.Eval(cel.NoVars())
if err == nil || !strings.Contains(err.Error(), tc.err) {
var got any = err
if err == nil {
got = out
}
t.Fatalf("prg.Eval() got %v, wanted error %v", got, tc.err)
}
})
}
}
func TestNativeTypesErrors(t *testing.T) {
envTests := []struct {
nativeType any
err string
}{
{
nativeType: reflect.TypeOf(1),
err: "unsupported reflect.Type",
},
{
nativeType: reflect.ValueOf(1),
err: "unsupported reflect.Type",
},
{
nativeType: 1,
err: "must be reflect.Type or reflect.Value",
},
}
for i, tst := range envTests {
tc := tst
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
_, err := cel.NewEnv(NativeTypes(tc.nativeType))
if err == nil || !strings.Contains(err.Error(), tc.err) {
t.Errorf("cel.NewEnv(NativeTypes(%v)) got error %v, wanted %v", tc.nativeType, err, tc.err)
}
})
}
}
func TestNativeTypesConvertToNative(t *testing.T) {
env := testNativeEnv(t, NativeTypes(reflect.TypeOf(TestNestedType{})))
adapter := env.CELTypeAdapter()
conversions := []struct {
in any
out any
err string
}{
{
in: &TestAllTypes{BoolVal: true},
out: &TestAllTypes{BoolVal: true},
},
{
in: TestAllTypes{BoolVal: true},
out: &TestAllTypes{BoolVal: true},
},
{
in: &TestAllTypes{BoolVal: true},
out: TestAllTypes{BoolVal: true},
},
{
in: nil,
out: types.NullValue,
},
{
in: &TestAllTypes{BoolVal: true},
out: &proto3pb.TestAllTypes{},
err: "type conversion error",
},
}
for _, c := range conversions {
inVal := adapter.NativeToValue(c.in)
if types.IsError(inVal) {
t.Fatalf("adapter.NativeToValue(%v) failed: %v", c.in, inVal)
}
out, err := inVal.ConvertToNative(reflect.TypeOf(c.out))
if err != nil {
if c.err != "" {
if !strings.Contains(err.Error(), c.err) {
t.Fatalf("%v.ConvertToNative(%T) got %v, wanted error %v", c.in, c.out, err, c.err)
}
return
}
t.Fatalf("%v.ConvertToNative(%T) failed: %v", c.in, c.out, err)
}
if !reflect.DeepEqual(out, c.out) {
t.Errorf("%v.ConvertToNative(%T) got %v, wanted %v", c.in, c.out, out, c.out)
}
}
}
func TestConvertToTypeErrors(t *testing.T) {
env := testNativeEnv(t, NativeTypes(reflect.TypeOf(TestNestedType{})))
adapter := env.CELTypeAdapter()
conversions := []struct {
in any
out any
err string
}{
{
in: &TestAllTypes{BoolVal: true},
out: &TestAllTypes{BoolVal: true},
},
{
in: TestAllTypes{BoolVal: true},
out: &TestAllTypes{BoolVal: true},
},
{
in: &TestAllTypes{BoolVal: true},
out: TestAllTypes{BoolVal: true},
},
{
in: &TestAllTypes{BoolVal: true},
out: &proto3pb.TestAllTypes{},
err: "type conversion error",
},
}
for _, c := range conversions {
inVal := adapter.NativeToValue(c.in)
outVal := adapter.NativeToValue(c.out)
if types.IsError(inVal) {
t.Fatalf("adapter.NativeToValue(%v) failed: %v", c.in, inVal)
}
if types.IsError(outVal) {
t.Fatalf("adapter.NativeToValue(%v) failed: %v", c.out, outVal)
}
conv := inVal.ConvertToType(outVal.Type())
if c.err != "" {
if !types.IsError(conv) {
t.Fatalf("%v.ConvertToType(%v) got %v, wanted error %v", c.in, outVal.Type(), conv, c.err)
}
convErr := conv.(*types.Err)
if !strings.Contains(convErr.Error(), c.err) {
t.Fatalf("%v.ConvertToType(%v) got %v, wanted error %v", c.in, outVal.Type(), conv, c.err)
}
return
}
if conv != inVal {
t.Errorf("%v.ConvertToType(%v) got %v, wanted %v", c.in, outVal.Type(), conv, c.err)
}
conv = inVal.ConvertToType(types.TypeType)
if conv.Type() != types.TypeType || conv.(ref.Type) != inVal.Type() {
t.Errorf("%v.ConvertToType(Type) got %v, wanted %v", inVal, conv, inVal.Type())
}
}
}
func TestNativeTypesWithOptional(t *testing.T) {
var nativeTests = []struct {
expr string
}{
{expr: `!optional.ofNonZeroValue(ext.TestAllTypes{}).hasValue()`},
{expr: `!ext.TestAllTypes{}.?BoolVal.orValue(false)`},
{expr: `!ext.TestAllTypes{}.?BoolVal.hasValue()`},
{expr: `!ext.TestAllTypes{BoolVal: false}.?BoolVal.hasValue()`},
{expr: `ext.TestAllTypes{BoolVal: true}.?BoolVal.hasValue()`},
{expr: `ext.TestAllTypes{}.NestedVal.?NestedMapVal.orValue({}).size() == 0`},
}
env := testNativeEnv(t, cel.OptionalTypes())
for i, tst := range nativeTests {
tc := tst
t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) {
var asts []*cel.Ast
pAst, iss := env.Parse(tc.expr)
if iss.Err() != nil {
t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err())
}
asts = append(asts, pAst)
cAst, iss := env.Check(pAst)
if iss.Err() != nil {
t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err())
}
asts = append(asts, cAst)
for _, ast := range asts {
prg, err := env.Program(ast)
if err != nil {
t.Fatal(err)
}
out, _, err := prg.Eval(cel.NoVars())
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(out.Value(), true) {
t.Errorf("got %v, wanted true for expr: %s", out.Value(), tc.expr)
}
}
})
}
}
func TestNativeTypeConvertToType(t *testing.T) {
nt, err := newNativeType(reflect.TypeOf(&TestAllTypes{}))
if err != nil {
t.Fatalf("newNativeType() failed: %v", err)
}
if nt.ConvertToType(types.TypeType) != types.TypeType {
t.Error("ConvertToType(Type) failed")
}
if !types.IsError(nt.ConvertToType(types.StringType)) {
t.Errorf("ConvertToType(String) got %v, wanted error", nt.ConvertToType(types.StringType))
}
}
func TestNativeTypeConvertToNative(t *testing.T) {
nt, err := newNativeType(reflect.TypeOf(&TestAllTypes{}))
if err != nil {
t.Fatalf("newNativeType() failed: %v", err)
}
out, err := nt.ConvertToNative(reflect.TypeOf(1))
if err == nil {
t.Errorf("nt.ConvertToNative(1) produced %v, wanted error", out)
}
}
func TestNativeTypeHasTrait(t *testing.T) {
nt, err := newNativeType(reflect.TypeOf(&TestAllTypes{}))
if err != nil {
t.Fatalf("newNativeType() failed: %v", err)
}
if !nt.HasTrait(traits.IndexerType) || !nt.HasTrait(traits.FieldTesterType) {
t.Error("nt.HasTrait() failed indicate support for presence test and field access.")
}
}
func TestNativeTypeValue(t *testing.T) {
nt, err := newNativeType(reflect.TypeOf(&TestAllTypes{}))
if err != nil {
t.Fatalf("newNativeType() failed: %v", err)
}
if nt.Value() != nt.String() {
t.Errorf("nt.Value() got %v, wanted %v", nt.Value(), nt.String())
}
}
// testEnv initializes the test environment common to all tests.
func testNativeEnv(t *testing.T, opts ...cel.EnvOption) *cel.Env {
t.Helper()
envOpts := []cel.EnvOption{
cel.Container("ext"),
cel.Abbrevs("google.expr.proto3.test"),
cel.Types(&proto3pb.TestAllTypes{}),
cel.Variable("tests", cel.ListType(cel.ObjectType("ext.TestAllTypes"))),
}
envOpts = append(envOpts, opts...)
envOpts = append(envOpts,
NativeTypes(
reflect.TypeOf(&TestNestedType{}),
reflect.ValueOf(&TestAllTypes{}),
),
)
env, err := cel.NewEnv(envOpts...)
if err != nil {
t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err)
}
return env
}
func mustParseTime(t *testing.T, timestamp string) time.Time {
t.Helper()
out, err := time.Parse(time.RFC3339, timestamp)
if err != nil {
t.Fatalf("time.Parse(%q) failed: %v", timestamp, err)
}
return out
}
type TestNestedType struct {
NestedListVal []string
NestedMapVal map[int64]bool
}
type TestAllTypes struct {
NestedVal *TestNestedType
NestedStructVal TestNestedType
BoolVal bool
BytesVal []byte
DurationVal time.Duration
DoubleVal float64
FloatVal float32
Int32Val int32
Int64Val int64
StringVal string
TimestampVal time.Time
Uint32Val uint32
Uint64Val uint64
ListVal []*TestNestedType
MapVal map[string]TestAllTypes
PbVal *proto3pb.TestAllTypes
// channel types are not supported
UnsupportedVal chan string
UnsupportedListVal []chan string
UnsupportedMapVal map[int]chan string
// unexported types can be found but not set or accessed
privateVal map[string]string
}
|