MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestAttributesOptional

Function TestAttributesOptional

interpreter/attributes_test.go:447–795  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

445}
446
447func TestAttributesOptional(t *testing.T) {
448 reg := newTestRegistry(t, types.ProtoTypeDefs(&proto3pb.TestAllTypes{}))
449 cont, err := containers.NewContainer(containers.Name("ns"))
450 if err != nil {
451 t.Fatalf("")
452 }
453 attrs := NewAttributeFactory(cont, reg, reg)
454 tests := []struct {
455 varName string
456 quals []any
457 optQuals []any
458 vars map[string]any
459 out any
460 err error
461 }{
462 {
463 // a.?b[0][false]
464 varName: "a",
465 optQuals: []any{"b", int32(0), false},
466 vars: map[string]any{
467 "a": map[string]any{
468 "b": map[int]any{
469 0: map[bool]string{
470 false: "success",
471 },
472 },
473 },
474 },
475 out: types.OptionalOf(reg.NativeToValue("success")),
476 },
477 {
478 // a.?b[0][false]
479 varName: "a",
480 optQuals: []any{"b", uint32(0), false},
481 vars: map[string]any{
482 "a": map[string]any{
483 "b": map[int]any{
484 0: map[bool]string{
485 false: "success",
486 },
487 },
488 },
489 },
490 out: types.OptionalOf(reg.NativeToValue("success")),
491 },
492 {
493 // a.?b[0][false]
494 varName: "a",
495 optQuals: []any{"b", float32(0), false},
496 vars: map[string]any{
497 "a": map[string]any{
498 "b": map[int]any{
499 0: map[bool]string{
500 false: "success",
501 },
502 },
503 },
504 },

Callers

nothing calls this directly

Calls 15

AbsoluteAttributeMethod · 0.95
ConditionalAttributeMethod · 0.95
MaybeAttributeMethod · 0.95
ProtoTypeDefsFunction · 0.92
NewContainerFunction · 0.92
NameFunction · 0.92
OptionalOfFunction · 0.92
NewObjectTypeFunction · 0.92
NewAttributeFactoryFunction · 0.85
NewConstValueFunction · 0.85
addQualifierFunction · 0.85
makeQualifierFunction · 0.85

Tested by

no test coverage detected