Skip to content

Commit

Permalink
added local test for get tools from toolhouse
Browse files Browse the repository at this point in the history
  • Loading branch information
conneroisu committed Oct 26, 2024
1 parent 1533a32 commit d593b6b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions extensions/toolhouse/tools_test.go
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)

Check warning on line 50 in extensions/toolhouse/tools_test.go

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 19 lines is too similar to extensions/toolhouse/run_test.go:34
a.NotEmpty(tools)
}

0 comments on commit d593b6b

Please sign in to comment.