Update tests to use context and correct URL references

- Modified the `createTestContext` function to use `context.Background()` for improved context management in tests.
- Updated the URL in the `TestAddURL` function to point to the correct Yao Agent Caller resource, ensuring accurate test assertions for added URLs.
This commit is contained in:
Max 2025-12-19 20:10:16 +08:00
parent 493f9dbea2
commit fa471bc4c4
2 changed files with 6 additions and 5 deletions

View file

@ -1,6 +1,7 @@
package web_test package web_test
import ( import (
"context"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -278,7 +279,7 @@ func createTestContext(t *testing.T) *agentContext.Context {
UserID: "test-user", UserID: "test-user",
TenantID: "test-tenant", TenantID: "test-tenant",
} }
ctx := agentContext.New(nil, authorized, "test-chat-id") ctx := agentContext.New(context.Background(), authorized, "test-chat-id")
ctx.AssistantID = "tests.web-agent-caller" ctx.AssistantID = "tests.web-agent-caller"
return ctx return ctx
} }

View file

@ -67,10 +67,10 @@ func TestAddURL(t *testing.T) {
t.Run("AddURLSuccess", func(t *testing.T) { t.Run("AddURLSuccess", func(t *testing.T) {
params := &api.AddURLParams{ params := &api.AddURLParams{
CollectionID: collectionID, CollectionID: collectionID,
URL: "https://example.com", URL: "https://raw.githubusercontent.com/trheyi/yao/refs/heads/main/agent/caller/caller.go",
Locale: "en", Locale: "en",
Metadata: map[string]interface{}{ Metadata: map[string]interface{}{
"title": "Example Website", "title": "Yao Agent Caller",
"description": "A test URL document", "description": "A test URL document",
}, },
Chunking: &api.ProviderConfigParams{ Chunking: &api.ProviderConfigParams{
@ -96,7 +96,7 @@ func TestAddURL(t *testing.T) {
if result != nil { if result != nil {
assert.Equal(t, collectionID, result.CollectionID) assert.Equal(t, collectionID, result.CollectionID)
assert.NotEmpty(t, result.DocID) assert.NotEmpty(t, result.DocID)
assert.Equal(t, "https://example.com", result.URL) assert.Equal(t, "https://raw.githubusercontent.com/trheyi/yao/refs/heads/main/agent/caller/caller.go", result.URL)
assert.Contains(t, result.Message, "successfully") assert.Contains(t, result.Message, "successfully")
t.Logf("Added URL document: %s", result.DocID) t.Logf("Added URL document: %s", result.DocID)
} }
@ -107,7 +107,7 @@ func TestAddURL(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, doc) assert.NotNil(t, doc)
assert.Equal(t, "url", doc["type"]) assert.Equal(t, "url", doc["type"])
assert.Equal(t, "https://example.com", doc["url"]) assert.Equal(t, "https://raw.githubusercontent.com/trheyi/yao/refs/heads/main/agent/caller/caller.go", doc["url"])
t.Logf("✅ URL Document verified: type=%v, url=%v, status=%v", doc["type"], doc["url"], doc["status"]) t.Logf("✅ URL Document verified: type=%v, url=%v, status=%v", doc["type"], doc["url"], doc["status"])
} }
}) })