Skip to content

Commit

Permalink
Add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Dec 18, 2023
1 parent 55973e6 commit 07976e0
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions model/chatmodel/fake_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package chatmodel

import (
"context"
"testing"

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

func TestFake(t *testing.T) {
t.Run("Generate_Success", func(t *testing.T) {
// Arrange
fake := NewSimpleFake("response")

// Act
result, err := fake.Generate(context.Background(), schema.ChatMessages{})

// Assert
assert.NoError(t, err)
assert.NotNil(t, result)
assert.Equal(t, "response", result.Generations[0].Text)
})

t.Run("Generate_CustomResultFunc", func(t *testing.T) {
// Arrange
expectedResult := &schema.ModelResult{
Generations: []schema.Generation{{Text: "custom_response"}},
}
fake := NewFake(func(ctx context.Context, messages schema.ChatMessages) (*schema.ModelResult, error) {
return expectedResult, nil
})

// Act
result, err := fake.Generate(context.Background(), schema.ChatMessages{})

// Assert
assert.NoError(t, err)
assert.NotNil(t, result)
assert.Equal(t, "custom_response", result.Generations[0].Text)
})

t.Run("Generate_ErrorFromResultFunc", func(t *testing.T) {
// Arrange
expectedError := assert.AnError
fake := NewFake(func(ctx context.Context, messages schema.ChatMessages) (*schema.ModelResult, error) {
return nil, expectedError
})

// Act
result, err := fake.Generate(context.Background(), schema.ChatMessages{})

// Assert
assert.Error(t, err)
assert.Nil(t, result)
assert.EqualError(t, err, expectedError.Error())
})

t.Run("Type", func(t *testing.T) {
// Arrange
fake := NewSimpleFake("response")

// Act
result := fake.Type()

// Assert
assert.Equal(t, "chatmodel.Fake", result)
})

t.Run("Verbose", func(t *testing.T) {
// Arrange
fake := NewSimpleFake("response")

// Act
result := fake.Verbose()

// Assert
assert.Equal(t, golc.Verbose, result)
})

t.Run("Callbacks", func(t *testing.T) {
// Arrange
fake := NewSimpleFake("response")

// Act
result := fake.Callbacks()

// Assert
assert.Empty(t, result)
})

t.Run("InvocationParams", func(t *testing.T) {
// Arrange
fake := NewSimpleFake("response")

// Act
result := fake.InvocationParams()

// Assert
assert.Empty(t, result)
})
}

0 comments on commit 07976e0

Please sign in to comment.