Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jun 16, 2023
1 parent 353e306 commit 37354e7
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions chain/transform_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package chain

import (
"context"
"testing"

"github.com/hupe1980/golc"
"github.com/stretchr/testify/assert"
)

func TestTransformChain(t *testing.T) {
t.Run("InputKeys", func(t *testing.T) {
// Test case: InputKeys returns the expected input keys
inputKeys := []string{"input1", "input2"}
outputKeys := []string{"output1", "output2"}

transform := func(inputs golc.ChainValues) (golc.ChainValues, error) {
return nil, nil
}

chain, err := NewTransformChain(inputKeys, outputKeys, transform)
assert.NoError(t, err)

expectedInputKeys := []string{"input1", "input2"}

result := chain.InputKeys()
assert.Equal(t, expectedInputKeys, result)
})

t.Run("OutputKeys", func(t *testing.T) {
// Test case: OutputKeys returns the expected output keys
inputKeys := []string{"input1", "input2"}
outputKeys := []string{"output1", "output2"}

transform := func(inputs golc.ChainValues) (golc.ChainValues, error) {
return nil, nil
}

chain, err := NewTransformChain(inputKeys, outputKeys, transform)
assert.NoError(t, err)

expectedOutputKeys := []string{"output1", "output2"}

result := chain.OutputKeys()
assert.Equal(t, expectedOutputKeys, result)
})

t.Run("Call", func(t *testing.T) {
// Test case: Call invokes the transform function and returns the result
inputKeys := []string{"input1", "input2"}
outputKeys := []string{"output1", "output2"}

transform := func(inputs golc.ChainValues) (golc.ChainValues, error) {
result := make(golc.ChainValues)
result["output1"] = inputs["input1"].(string) + "-transformed"
result["output2"] = inputs["input2"].(int) * 2
return result, nil
}

chain, err := NewTransformChain(inputKeys, outputKeys, transform)
assert.NoError(t, err)

inputs := make(golc.ChainValues)
inputs["input1"] = "value1"
inputs["input2"] = 5

expectedResult := make(golc.ChainValues)
expectedResult["output1"] = "value1-transformed"
expectedResult["output2"] = 10

result, err := chain.Call(context.Background(), inputs)
assert.NoError(t, err)
assert.Equal(t, expectedResult, result)
})
}

0 comments on commit 37354e7

Please sign in to comment.