@@ -43,9 +43,9 @@ func TestMain(m *testing.M) {
43
43
44
44
// Get secrets and auth tokens
45
45
log .Println ("Fetching secrets and auth tokens..." )
46
- toolsManifestContent := accessSecretVersion (ctx , projectID , "sdk_testing_tools" )
47
- clientID1 := accessSecretVersion (ctx , projectID , "sdk_testing_client1" )
48
- clientID2 := accessSecretVersion (ctx , projectID , "sdk_testing_client2" )
46
+ toolsManifestContent := accessSecretVersion (ctx , projectID , "sdk_testing_tools" , "34" )
47
+ clientID1 := accessSecretVersion (ctx , projectID , "sdk_testing_client1" , "latest" )
48
+ clientID2 := accessSecretVersion (ctx , projectID , "sdk_testing_client2" , "latest" )
49
49
authToken1 = getAuthToken (ctx , clientID1 )
50
50
authToken2 = getAuthToken (ctx , clientID2 )
51
51
@@ -78,7 +78,6 @@ func TestMain(m *testing.M) {
78
78
os .Exit (exitCode )
79
79
}
80
80
81
- // TestE2E_Basic maps to the TestBasicE2E class
82
81
func TestE2E_Basic (t * testing.T ) {
83
82
// Helper to create a new client for each sub-test, like a function-scoped fixture
84
83
newClient := func (t * testing.T ) * core.ToolboxClient {
@@ -132,7 +131,7 @@ func TestE2E_Basic(t *testing.T) {
132
131
toolset , err := client .LoadToolset ("" , context .Background ())
133
132
require .NoError (t , err )
134
133
135
- assert .Len (t , toolset , 6 )
134
+ assert .Len (t , toolset , 7 )
136
135
toolNames := make (map [string ]struct {})
137
136
for _ , tool := range toolset {
138
137
toolNames [tool .Name ()] = struct {}{}
@@ -144,6 +143,7 @@ func TestE2E_Basic(t *testing.T) {
144
143
"get-row-by-id" : {},
145
144
"get-n-rows" : {},
146
145
"search-rows" : {},
146
+ "process-data" : {},
147
147
}
148
148
assert .Equal (t , expectedTools , toolNames )
149
149
})
@@ -182,7 +182,6 @@ func TestE2E_Basic(t *testing.T) {
182
182
})
183
183
}
184
184
185
- // TestE2E_BindParams maps to the TestBindParams class
186
185
func TestE2E_BindParams (t * testing.T ) {
187
186
newClient := func (t * testing.T ) * core.ToolboxClient {
188
187
client , err := core .NewToolboxClient ("http://localhost:5000" )
@@ -236,7 +235,6 @@ func TestE2E_BindParams(t *testing.T) {
236
235
})
237
236
}
238
237
239
- // TestE2E_Auth maps to the TestAuth class
240
238
func TestE2E_Auth (t * testing.T ) {
241
239
newClient := func (t * testing.T ) * core.ToolboxClient {
242
240
client , err := core .NewToolboxClient ("http://localhost:5000" )
@@ -338,7 +336,6 @@ func TestE2E_Auth(t *testing.T) {
338
336
})
339
337
}
340
338
341
- // TestE2E_OptionalParams maps to the TestOptionalParams class
342
339
func TestE2E_OptionalParams (t * testing.T ) {
343
340
// Helper to create a new client
344
341
newClient := func (t * testing.T ) * core.ToolboxClient {
@@ -475,3 +472,112 @@ func TestE2E_OptionalParams(t *testing.T) {
475
472
assert .Equal (t , "null" , response , "Response should be null for non-matching data" )
476
473
})
477
474
}
475
+
476
+ func TestE2E_MapParams (t * testing.T ) {
477
+ // Helper to create a new client
478
+ newClient := func (t * testing.T ) * core.ToolboxClient {
479
+ client , err := core .NewToolboxClient ("http://localhost:5000" )
480
+ require .NoError (t , err , "Failed to create ToolboxClient" )
481
+ return client
482
+ }
483
+
484
+ // Helper to load the process-data tool
485
+ processDataTool := func (t * testing.T , client * core.ToolboxClient ) * core.ToolboxTool {
486
+ tool , err := client .LoadTool ("process-data" , context .Background ())
487
+ require .NoError (t , err , "Failed to load tool 'process-data'" )
488
+ return tool
489
+ }
490
+
491
+ t .Run ("test_tool_schema_is_correct" , func (t * testing.T ) {
492
+ client := newClient (t )
493
+ tool := processDataTool (t , client )
494
+ params := tool .Parameters ()
495
+
496
+ // Convert slice to map for easy lookup
497
+ paramMap := make (map [string ]core.ParameterSchema )
498
+ for _ , p := range params {
499
+ paramMap [p .Name ] = p
500
+ }
501
+
502
+ // Verify 'execution_context' parameter.
503
+ execCtxParam , ok := paramMap ["execution_context" ]
504
+ require .True (t , ok , "'execution_context' parameter should exist" )
505
+ assert .True (t , execCtxParam .Required , "'execution_context' should be required" )
506
+ assert .Equal (t , "object" , execCtxParam .Type , "'execution_context' type should be object" )
507
+
508
+ // Verify 'user_scores' parameter.
509
+ userScoresParam , ok := paramMap ["user_scores" ]
510
+ require .True (t , ok , "'user_scores' parameter should exist" )
511
+ assert .True (t , userScoresParam .Required , "'user_scores' should be required" )
512
+ assert .Equal (t , "object" , userScoresParam .Type , "'user_scores' type should be object" )
513
+
514
+ // Verify 'feature_flags' parameter.
515
+ featureFlagsParam , ok := paramMap ["feature_flags" ]
516
+ require .True (t , ok , "'feature_flags' parameter should exist" )
517
+ assert .False (t , featureFlagsParam .Required , "'feature_flags' should be optional" )
518
+ assert .Equal (t , "object" , featureFlagsParam .Type , "'feature_flags' type should be object" )
519
+ })
520
+
521
+ t .Run ("test_run_tool_with_all_map_params" , func (t * testing.T ) {
522
+ client := newClient (t )
523
+ tool := processDataTool (t , client )
524
+
525
+ // Invoke the tool with valid map parameters.
526
+ response , err := tool .Invoke (context .Background (), map [string ]any {
527
+ "execution_context" : map [string ]any {
528
+ "env" : "prod" ,
529
+ "id" : 1234 ,
530
+ "user" : 1234.5 ,
531
+ },
532
+ "user_scores" : map [string ]any {
533
+ "user1" : 100 ,
534
+ "user2" : 200 ,
535
+ },
536
+ "feature_flags" : map [string ]any {
537
+ "new_feature" : true ,
538
+ },
539
+ })
540
+ require .NoError (t , err )
541
+ respStr , ok := response .(string )
542
+ require .True (t , ok , "Response should be a string" )
543
+
544
+ assert .Contains (t , respStr , `"execution_context":{"env":"prod","id":1234,"user":1234.5}` )
545
+ assert .Contains (t , respStr , `"user_scores":{"user1":100,"user2":200}` )
546
+ assert .Contains (t , respStr , `"feature_flags":{"new_feature":true}` )
547
+ })
548
+
549
+ t .Run ("test_run_tool_omitting_optional_map" , func (t * testing.T ) {
550
+ client := newClient (t )
551
+ tool := processDataTool (t , client )
552
+
553
+ // Invoke the tool without the optional 'feature_flags' parameter.
554
+ response , err := tool .Invoke (context .Background (), map [string ]any {
555
+ "execution_context" : map [string ]any {"env" : "dev" },
556
+ "user_scores" : map [string ]any {"user3" : 300 },
557
+ })
558
+ require .NoError (t , err )
559
+ respStr , ok := response .(string )
560
+ require .True (t , ok , "Response should be a string" )
561
+
562
+ assert .Contains (t , respStr , `"execution_context":{"env":"dev"}` )
563
+ assert .Contains (t , respStr , `"user_scores":{"user3":300}` )
564
+ assert .Contains (t , respStr , `"feature_flags":null` )
565
+ })
566
+
567
+ t .Run ("test_run_tool_with_wrong_map_value_type" , func (t * testing.T ) {
568
+ client := newClient (t )
569
+ tool := processDataTool (t , client )
570
+
571
+ // Attempt to invoke the tool with an incorrect type in a map value.
572
+ _ , err := tool .Invoke (context .Background (), map [string ]any {
573
+ "execution_context" : map [string ]any {"env" : "staging" },
574
+ "user_scores" : map [string ]any {
575
+ "user4" : "not-an-integer" ,
576
+ },
577
+ })
578
+
579
+ // Assert that an error was returned.
580
+ require .Error (t , err , "Expected an error for wrong map value type" )
581
+ assert .Contains (t , err .Error (), "expects an integer, but got string" , "Error message should indicate a validation failure" )
582
+ })
583
+ }
0 commit comments