Skip to content

Commit

Permalink
Add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Dec 10, 2023
1 parent 35a9f53 commit 605af05
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion memory/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestConversationBuffer(t *testing.T) {
})

t.Run("LoadMemoryVariables", func(t *testing.T) {
inputs := map[string]interface{}{}
inputs := map[string]any{}

messages := schema.ChatMessages{
schema.NewHumanChatMessage("Hello"),
Expand Down
45 changes: 45 additions & 0 deletions memory/readonly_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package memory

import (
"context"
"testing"

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

func TestReadonly(t *testing.T) {
ctx := context.Background()

mockMemory := NewConversationBuffer()
err := mockMemory.SaveContext(ctx, map[string]any{"input": "foo"}, map[string]any{"output": "bar"})
assert.NoError(t, err)

readonly := NewReadonly(mockMemory)

t.Run("MemoryKeys", func(t *testing.T) {
assert.Equal(t, mockMemory.MemoryKeys(), readonly.MemoryKeys())
})

t.Run("LoadMemoryVariables", func(t *testing.T) {
mockInputs := map[string]any{"key": "value"}
result, err := readonly.LoadMemoryVariables(ctx, mockInputs)
assert.NoError(t, err)
assert.Equal(t, "Human: foo\nAI: bar", result["history"])
})

t.Run("SaveContext", func(t *testing.T) {
err := readonly.SaveContext(ctx, map[string]any{"input": "Not saved"}, map[string]any{"output": "Not saved"})
assert.NoError(t, err)
result, err := readonly.LoadMemoryVariables(ctx, map[string]any{})
assert.NoError(t, err)
assert.Equal(t, "Human: foo\nAI: bar", result["history"])
})

t.Run("Clear", func(t *testing.T) {
err := readonly.Clear(ctx)
assert.NoError(t, err)
result, err := readonly.LoadMemoryVariables(ctx, map[string]any{})
assert.NoError(t, err)
assert.Equal(t, "Human: foo\nAI: bar", result["history"])
})
}

0 comments on commit 605af05

Please sign in to comment.