MCPcopy Index your code
hub / github.com/coder/coder / testTool

Function testTool

codersdk/toolsdk/toolsdk_test.go:2372–2381  ·  view source on GitHub ↗

testTool is a helper function to test a tool and mark it as tested. Note that we test the _generic_ version of the tool and not the typed one. This is to mimic how we expect external callers to use the tool.

(t *testing.T, tool toolsdk.Tool[Arg, Ret], tb toolsdk.Deps, args Arg)

Source from the content-addressed store, hash-verified

2370// Note that we test the _generic_ version of the tool and not the typed one.
2371// This is to mimic how we expect external callers to use the tool.
2372func testTool[Arg, Ret any](t *testing.T, tool toolsdk.Tool[Arg, Ret], tb toolsdk.Deps, args Arg) (Ret, error) {
2373 t.Helper()
2374 defer func() { testedTools.Store(tool.Name, true) }()
2375 toolArgs, err := json.Marshal(args)
2376 require.NoError(t, err, "failed to marshal args")
2377 result, err := tool.Generic().Handler(t.Context(), tb, toolArgs)
2378 var ret Ret
2379 require.NoError(t, json.Unmarshal(result, &ret), "failed to unmarshal result %q", string(result))
2380 return ret, err
2381}
2382
2383func TestWithRecovery(t *testing.T) {
2384 t.Parallel()

Calls 7

GenericMethod · 0.80
HelperMethod · 0.65
ContextMethod · 0.65
StoreMethod · 0.45
MarshalMethod · 0.45
HandlerMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected