Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae06274

Browse files
committed
fix toolsdk testmain
1 parent 82803da commit ae06274

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

codersdk/toolsdk/toolsdk.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,25 @@ func (t Tool[T]) Generic() Tool[any] {
3232
}
3333

3434
var (
35+
// All is a list of all tools that can be used in the Coder CLI.
36+
// When you add a new tool, be sure to include it here!
3537
All = []Tool[any]{
36-
ReportTask.Generic(),
38+
CreateTemplateVersion.Generic(),
39+
CreateTemplate.Generic(),
3740
CreateWorkspace.Generic(),
41+
CreateWorkspaceBuild.Generic(),
42+
DeleteTemplate.Generic(),
43+
GetAuthenticatedUser.Generic(),
44+
GetTemplateVersionLogs.Generic(),
45+
GetWorkspace.Generic(),
46+
GetWorkspaceAgentLogs.Generic(),
47+
GetWorkspaceBuildLogs.Generic(),
3848
ListWorkspaces.Generic(),
3949
ListTemplates.Generic(),
4050
ListTemplateVersionParameters.Generic(),
41-
GetAuthenticatedUser.Generic(),
42-
CreateWorkspaceBuild.Generic(),
51+
ReportTask.Generic(),
4352
UploadTarFile.Generic(),
44-
CreateTemplateVersion.Generic(),
45-
CreateTemplate.Generic(),
46-
GetTemplateVersionLogs.Generic(),
4753
UpdateTemplateActiveVersion.Generic(),
48-
DeleteTemplate.Generic(),
49-
GetWorkspaceAgentLogs.Generic(),
50-
GetWorkspaceBuildLogs.Generic(),
5154
}
5255

5356
ReportTask = Tool[string]{

codersdk/toolsdk/toolsdk_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,25 @@ var testedTools sync.Map
329329
// testTool is a helper function to test a tool and mark it as tested.
330330
func testTool[T any](ctx context.Context, t *testing.T, tool toolsdk.Tool[T], args map[string]any) (T, error) {
331331
t.Helper()
332-
testedTools.Store(tool.Tool.Name, struct{}{})
332+
testedTools.Store(tool.Tool.Name, true)
333333
result, err := tool.Handler(ctx, args)
334334
return result, err
335335
}
336336

337337
// TestMain runs after all tests to ensure that all tools in this package have
338338
// been tested once.
339339
func TestMain(m *testing.M) {
340+
// Initialize testedTools
341+
for _, tool := range toolsdk.All {
342+
testedTools.Store(tool.Tool.Name, false)
343+
}
344+
340345
code := m.Run()
346+
347+
// Ensure all tools have been tested
341348
var untested []string
342349
for _, tool := range toolsdk.All {
343-
if _, ok := testedTools.Load(tool.Tool.Name); !ok {
350+
if tested, ok := testedTools.Load(tool.Tool.Name); !ok || !tested.(bool) {
344351
untested = append(untested, tool.Tool.Name)
345352
}
346353
}

0 commit comments

Comments
 (0)