Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
fanweixiao committed Mar 22, 2024
1 parent 689d510 commit 4e520a7
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/bridge/ai/provider/cfopenai/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cfopenai

import (
"os"
"testing"

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

func TestCloudflareOpenAIProvider_Name(t *testing.T) {
provider := &CloudflareOpenAIProvider{}

name := provider.Name()

assert.Equal(t, "cloudflare_openai", name)
}

func TestNewProvider(t *testing.T) {
t.Run("with parameters", func(t *testing.T) {
provider := NewProvider("test_endpoint", "test_api_key", "test_model")

assert.Equal(t, "test_endpoint", provider.CfEndpoint)
assert.Equal(t, "test_api_key", provider.APIKey)
assert.Equal(t, "test_model", provider.Model)
})

t.Run("with environment variables", func(t *testing.T) {
os.Setenv("OPENAI_API_KEY", "env_api_key")
os.Setenv("OPENAI_MODEL", "env_model")

provider := NewProvider("test_endpoint", "", "")

assert.Equal(t, "test_endpoint", provider.CfEndpoint)
assert.Equal(t, "env_api_key", provider.APIKey)
assert.Equal(t, "env_model", provider.Model)

os.Unsetenv("OPENAI_API_KEY")
os.Unsetenv("OPENAI_MODEL")
})

t.Run("without cfEndpoint", func(t *testing.T) {
if os.Getenv("CI") != "true" {
t.Skip("Skipping testing in CI environment")
}

assert.Panics(t, func() {
NewProvider("", "test_api_key", "test_model")
})
})
}

0 comments on commit 4e520a7

Please sign in to comment.