(t *testing.T)
| 1371 | } |
| 1372 | |
| 1373 | func TestConditionalAttributeQualify(t *testing.T) { |
| 1374 | reg, _ := types.NewRegistry() |
| 1375 | cont := containers.DefaultContainer |
| 1376 | fac := NewAttributeFactory(cont, reg, reg) |
| 1377 | |
| 1378 | truthy := fac.AbsoluteAttribute(1, "a") |
| 1379 | falsy := fac.AbsoluteAttribute(2, "b") |
| 1380 | cond := &conditionalAttribute{ |
| 1381 | id: 3, |
| 1382 | expr: NewConstValue(4, types.True), |
| 1383 | truthy: truthy, |
| 1384 | falsy: falsy, |
| 1385 | adapter: reg, |
| 1386 | fac: fac, |
| 1387 | } |
| 1388 | |
| 1389 | activation, _ := NewActivation(map[string]any{"a": "key", "b": "other"}) |
| 1390 | obj := map[string]any{"key": 100} |
| 1391 | |
| 1392 | // Test Qualify |
| 1393 | res, err := cond.Qualify(activation, obj) |
| 1394 | if err != nil { |
| 1395 | t.Fatalf("Qualify() failed: %v", err) |
| 1396 | } |
| 1397 | if res != 100 { |
| 1398 | t.Errorf("Qualify() returned %v, wanted 100", res) |
| 1399 | } |
| 1400 | |
| 1401 | // Test QualifyIfPresent |
| 1402 | res, found, err := cond.QualifyIfPresent(activation, obj, false) |
| 1403 | if err != nil { |
| 1404 | t.Fatalf("QualifyIfPresent() failed: %v", err) |
| 1405 | } |
| 1406 | if !found || res != 100 { |
| 1407 | t.Errorf("QualifyIfPresent() returned (%v, %v), wanted (100, true)", res, found) |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | func TestQualifyIfPresent(t *testing.T) { |
| 1412 | reg := newTestRegistry(t) |
nothing calls this directly
no test coverage detected