(t *testing.T)
| 1456 | } |
| 1457 | |
| 1458 | func TestSingletonAsyncBinding(t *testing.T) { |
| 1459 | fn, err := NewFunction("async_fn", |
| 1460 | Overload("async_fn_int", []*types.Type{types.IntType}, types.IntType), |
| 1461 | Overload("async_fn_string", []*types.Type{types.StringType}, types.StringType), |
| 1462 | SingletonAsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val { |
| 1463 | return args[0] |
| 1464 | }), |
| 1465 | ) |
| 1466 | if err != nil { |
| 1467 | t.Fatalf("NewFunction() failed: %v", err) |
| 1468 | } |
| 1469 | if !fn.HasLateBinding() { |
| 1470 | t.Errorf("Function %s does not have late binding, wanted singleton async function to be late bound", fn.Name()) |
| 1471 | } |
| 1472 | bindings, err := fn.Bindings() |
| 1473 | if err != nil { |
| 1474 | t.Fatalf("fn.Bindings() produced an err: %v", err) |
| 1475 | } |
| 1476 | if len(bindings) != 1 { |
| 1477 | t.Errorf("fn.Bindings() produced %d bindings, wanted one", len(bindings)) |
| 1478 | } |
| 1479 | binding := bindings[0] |
| 1480 | if binding.Async == nil { |
| 1481 | t.Fatal("binding missing Async implementation") |
| 1482 | } |
| 1483 | |
| 1484 | ctx := context.Background() |
| 1485 | ch := binding.Async(ctx, types.String("hello")) |
| 1486 | select { |
| 1487 | case res := <-ch: |
| 1488 | if res.Equal(types.String("hello")) != types.True { |
| 1489 | t.Errorf("async binding returned %v, wanted hello", res) |
| 1490 | } |
| 1491 | case <-time.After(1 * time.Second): |
| 1492 | t.Fatal("async binding timed out") |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | func TestAsyncBindingRedefinition(t *testing.T) { |
| 1497 | _, err := NewFunction("async_fn", |
nothing calls this directly
no test coverage detected