mirror of
https://github.com/vxcontrol/langchaingo.git
synced 2026-07-21 00:45:22 -04:00
34 lines
633 B
Go
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)
|
|
}
|