websearch_test.go 1.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package tools

import (
	"errors"
	"testing"
)

func TestWebSearchTool_Name(t *testing.T) {
	tool := &WebSearchTool{}
	if tool.Name() != "web_search" {
		t.Errorf("expected name 'web_search', got '%s'", tool.Name())
	}
}

func TestWebSearchTool_Description(t *testing.T) {
	tool := &WebSearchTool{}
	if tool.Description() == "" {
		t.Error("expected non-empty description")
	}
}

func TestWebSearchTool_Execute_MissingQuery(t *testing.T) {
	tool := &WebSearchTool{}

	// Test with no query
	_, err := tool.Execute(map[string]any{})
	if err == nil {
		t.Error("expected error for missing query")
	}

	// Test with empty query
	_, err = tool.Execute(map[string]any{"query": ""})
	if err == nil {
		t.Error("expected error for empty query")
	}
}

func TestErrWebSearchAuthRequired(t *testing.T) {
	// Test that the error type exists and can be checked with errors.Is
	err := ErrWebSearchAuthRequired
	if err == nil {
		t.Fatal("ErrWebSearchAuthRequired should not be nil")
	}

	if err.Error() != "web search requires authentication" {
		t.Errorf("unexpected error message: %s", err.Error())
	}

	// Test that errors.Is works
	wrappedErr := errors.New("wrapped: " + err.Error())
	if errors.Is(wrappedErr, ErrWebSearchAuthRequired) {
		t.Error("wrapped error should not match with errors.Is")
	}

	if !errors.Is(ErrWebSearchAuthRequired, ErrWebSearchAuthRequired) {
		t.Error("ErrWebSearchAuthRequired should match itself with errors.Is")
	}
}