(t *testing.T)
| 1563 | } |
| 1564 | |
| 1565 | func TestConditionalAttributeQualify(t *testing.T) { |
| 1566 | reg, _ := types.NewRegistry() |
| 1567 | cont := containers.DefaultContainer |
| 1568 | fac := NewAttributeFactory(cont, reg, reg) |
| 1569 | |
| 1570 | truthy := fac.AbsoluteAttribute(1, "a") |
| 1571 | falsy := fac.AbsoluteAttribute(2, "b") |
| 1572 | cond := &conditionalAttribute{ |
| 1573 | id: 3, |
| 1574 | expr: NewConstValue(4, types.True), |
| 1575 | truthy: truthy, |
| 1576 | falsy: falsy, |
| 1577 | adapter: reg, |
| 1578 | fac: fac, |
| 1579 | } |
| 1580 | |
| 1581 | activation, _ := NewActivation(map[string]any{"a": "key", "b": "other"}) |
| 1582 | obj := map[string]any{"key": 100} |
| 1583 | |
| 1584 | // Test Qualify |
| 1585 | res, err := cond.Qualify(activation, obj) |
| 1586 | if err != nil { |
| 1587 | t.Fatalf("Qualify() failed: %v", err) |
| 1588 | } |
| 1589 | if res != 100 { |
| 1590 | t.Errorf("Qualify() returned %v, wanted 100", res) |
| 1591 | } |
| 1592 | |
| 1593 | // Test QualifyIfPresent |
| 1594 | res, found, err := cond.QualifyIfPresent(activation, obj, false) |
| 1595 | if err != nil { |
| 1596 | t.Fatalf("QualifyIfPresent() failed: %v", err) |
| 1597 | } |
| 1598 | if !found || res != 100 { |
| 1599 | t.Errorf("QualifyIfPresent() returned (%v, %v), wanted (100, true)", res, found) |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | func TestQualifyIfPresent(t *testing.T) { |
| 1604 | reg := newTestRegistry(t) |
nothing calls this directly
no test coverage detected