Files
langchaingo/chains/transform_test.go
T
2025-06-23 13:43:06 +03:00

34 lines
633 B
Go

package chains
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestTransform(t *testing.T) {
ctx := t.Context()
t.Parallel()
c := NewTransform(
func(_ context.Context, m map[string]any, _ ...ChainCallOption) (map[string]any, error) {
input, ok := m["input"].(string)
if !ok {
return nil, fmt.Errorf("%w: %w", ErrInvalidInputValues, ErrInputValuesWrongType)
}
return map[string]any{
"output": input + "foo",
}, nil
},
[]string{"input"},
[]string{"output"},
)
output, err := Run(ctx, c, "baz")
require.NoError(t, err)
require.Equal(t, "bazfoo", output)
}