-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added local test for get tools from toolhouse
- Loading branch information
1 parent
1533a32
commit d593b6b
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package toolhouse_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/conneroisu/groq-go/extensions/toolhouse" | ||
"github.com/conneroisu/groq-go/pkg/test" | ||
"github.com/conneroisu/groq-go/pkg/tools" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetTools(t *testing.T) { | ||
a := assert.New(t) | ||
ctx := context.Background() | ||
ts := test.NewTestServer() | ||
ts.RegisterHandler("/get_tools", func(w http.ResponseWriter, r *http.Request) { | ||
var ts []tools.Tool | ||
ts = append(ts, tools.Tool{ | ||
Function: tools.FunctionDefinition{ | ||
Name: "tool", | ||
Description: "tool", | ||
Parameters: tools.FunctionParameters{}, | ||
}, | ||
Type: tools.ToolTypeFunction, | ||
}) | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
jsonBytes, err := json.Marshal(ts) | ||
a.NoError(err) | ||
_, err = w.Write(jsonBytes) | ||
a.NoError(err) | ||
}) | ||
testS := ts.ToolhouseTestServer() | ||
testS.Start() | ||
client, err := toolhouse.NewExtension( | ||
test.GetTestToken(), | ||
toolhouse.WithBaseURL(testS.URL), | ||
toolhouse.WithClient(testS.Client()), | ||
toolhouse.WithLogger(test.DefaultLogger), | ||
toolhouse.WithMetadata(map[string]any{ | ||
"id": "conner", | ||
"timezone": 5, | ||
}), | ||
) | ||
a.NoError(err) | ||
tools, err := client.GetTools(ctx) | ||
a.NoError(err) | ||
a.NotEmpty(tools) | ||
} |