MCPcopy Index your code
hub / github.com/github/github-mcp-server / Test_OptionalNumberParamWithDefault

Function Test_OptionalNumberParamWithDefault

pkg/github/params_test.go:360–431  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

358}
359
360func Test_OptionalNumberParamWithDefault(t *testing.T) {
361 tests := []struct {
362 name string
363 params map[string]any
364 paramName string
365 defaultVal int
366 expected int
367 expectError bool
368 }{
369 {
370 name: "valid number parameter",
371 params: map[string]any{"count": float64(42)},
372 paramName: "count",
373 defaultVal: 10,
374 expected: 42,
375 expectError: false,
376 },
377 {
378 name: "valid string number parameter",
379 params: map[string]any{"count": "42"},
380 paramName: "count",
381 defaultVal: 10,
382 expected: 42,
383 expectError: false,
384 },
385 {
386 name: "missing parameter",
387 params: map[string]any{},
388 paramName: "count",
389 defaultVal: 10,
390 expected: 10,
391 expectError: false,
392 },
393 {
394 name: "zero value",
395 params: map[string]any{"count": float64(0)},
396 paramName: "count",
397 defaultVal: 10,
398 expected: 10,
399 expectError: false,
400 },
401 {
402 name: "zero string value uses default",
403 params: map[string]any{"count": "0"},
404 paramName: "count",
405 defaultVal: 10,
406 expected: 10,
407 expectError: false,
408 },
409 {
410 name: "wrong type parameter",
411 params: map[string]any{"count": "not-a-number"},
412 paramName: "count",
413 defaultVal: 10,
414 expected: 0,
415 expectError: true,
416 },
417 }

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.45

Tested by

no test coverage detected