Skip to content

Commit ad647a2

Browse files
authored
Make funcs in tests 'helpers' (#135)
1 parent 224be6c commit ad647a2

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

cmd/add_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ func (f *fakeBuilder) Build() (registry.PackageProvider, error) {
7272
return f.reg, f.err
7373
}
7474

75+
// testIntPtr returns a pointer to an int
76+
func testIntPtr(t *testing.T, i int) *int {
77+
t.Helper()
78+
return &i
79+
}
80+
7581
func TestAddCmd_Success(t *testing.T) {
7682
cfg := &fakeConfig{}
7783
pkg := packages.Server{
@@ -411,10 +417,6 @@ func TestSelectRuntime(t *testing.T) {
411417
}
412418
}
413419

414-
func intPtr(i int) *int {
415-
return &i
416-
}
417-
418420
func TestParseServerEntry(t *testing.T) {
419421
t.Parallel()
420422

@@ -533,8 +535,16 @@ func TestParseServerEntry(t *testing.T) {
533535
availableTools: []string{"read", "write"},
534536
requestedTools: []string{"read"},
535537
arguments: packages.Arguments{
536-
"path": {VariableType: packages.VariableTypeArgPositional, Position: intPtr(1), Required: true},
537-
"mode": {VariableType: packages.VariableTypeArgPositional, Position: intPtr(2), Required: true},
538+
"path": {
539+
VariableType: packages.VariableTypeArgPositional,
540+
Position: testIntPtr(t, 1),
541+
Required: true,
542+
},
543+
"mode": {
544+
VariableType: packages.VariableTypeArgPositional,
545+
Position: testIntPtr(t, 2),
546+
Required: true,
547+
},
538548
"--format": {VariableType: packages.VariableTypeArg, Required: true},
539549
"--encoding": {VariableType: packages.VariableTypeArg, Required: false},
540550
},

internal/provider/mcpm/registry_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
"github.com/mozilla-ai/mcpd/v2/internal/runtime"
1818
)
1919

20-
// intPtr returns a pointer to an int
21-
func intPtr(i int) *int {
20+
// testIntPtr returns a pointer to an int
21+
func testIntPtr(t *testing.T, i int) *int {
22+
t.Helper()
2223
return &i
2324
}
2425

@@ -447,7 +448,7 @@ func TestRegistry_ExtractArgumentMetadata_EdgeCases(t *testing.T) {
447448
Required: true,
448449
Description: "API key",
449450
Example: "key123",
450-
Position: intPtr(1),
451+
Position: testIntPtr(t, 1),
451452
},
452453
},
453454
},
@@ -577,15 +578,15 @@ func TestRegistry_ExtractArgumentMetadata_WithTestdata(t *testing.T) {
577578
Required: true,
578579
Description: "The base directory that the server will have access to",
579580
Example: "/Users/username/Documents",
580-
Position: intPtr(1),
581+
Position: testIntPtr(t, 1),
581582
},
582583
"USER_FILESYSTEM_ALLOWED_DIR": {
583584
Name: "USER_FILESYSTEM_ALLOWED_DIR",
584585
VariableType: packages.VariableTypeArgPositional,
585586
Required: false,
586587
Description: "Additional allowed directory for file access",
587588
Example: "/Users/username/Projects",
588-
Position: intPtr(2),
589+
Position: testIntPtr(t, 2),
589590
},
590591
},
591592
},
@@ -631,7 +632,7 @@ func TestRegistry_ExtractArgumentMetadata_WithTestdata(t *testing.T) {
631632
Required: true,
632633
Description: "Directory for data storage",
633634
Example: "/path/to/data",
634-
Position: intPtr(1),
635+
Position: testIntPtr(t, 1),
635636
},
636637
},
637638
},
@@ -752,7 +753,7 @@ func TestRegistry_ExtractArgumentMetadata_SyntheticCases(t *testing.T) {
752753
Required: true,
753754
Description: "Base directory",
754755
Example: "/path/to/files",
755-
Position: intPtr(1),
756+
Position: testIntPtr(t, 1),
756757
},
757758
},
758759
},
@@ -1080,15 +1081,15 @@ func TestRegistry_ExtractArgumentMetadata_ComprehensiveScenarios(t *testing.T) {
10801081
Required: true,
10811082
Description: "Base directory for files",
10821083
Example: "/path/to/files",
1083-
Position: intPtr(1),
1084+
Position: testIntPtr(t, 1),
10841085
},
10851086
"OPTIONAL_DIR": {
10861087
Name: "OPTIONAL_DIR",
10871088
VariableType: packages.VariableTypeArgPositional,
10881089
Required: false,
10891090
Description: "Optional directory",
10901091
Example: "/path/to/optional",
1091-
Position: intPtr(2),
1092+
Position: testIntPtr(t, 2),
10921093
},
10931094
}
10941095

0 commit comments

Comments
 (0)