-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
53 lines (46 loc) · 1.17 KB
/
client_test.go
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
package tavily
import (
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestBasicSearch(t *testing.T) {
sh := SearchHandler{}
ts := httptest.NewServer(http.HandlerFunc(sh.ServeHTTP))
defer ts.Close()
c := Client{
APIKey: "A fake API Key",
maxResults: 1,
searchDepth: "basic",
timeout: 30_000 * time.Millisecond,
tavilyURL: ts.URL,
}
testCases := []struct {
//a message which describes the test
msg string
//A payload to use in the test
req TavilyRequest
}{
{
msg: "Happy Path Simple Query",
req: TavilyRequest{
Query: "A Pretend Query",
},
},
}
for _, tc := range testCases {
if _, err := c.Search(tc.req.Query); err != nil {
t.Errorf("There was an error testing our search!Test: %s\nError:%s\n", tc.msg, err)
}
}
}
func TestNewClientSearch(t *testing.T) {
if _, err := NewClient(""); err == nil {
t.Error("Passed in an empty string and should have gotten an error!")
}
//TODO: Check that the API key has the correct format at least and isn't something silly
if _, err := NewClient("ladafafdfd"); err != nil {
t.Errorf("Should have gotten a proper client with no errors but did not!\nError: %s", err)
}
}