MCPcopy
hub / github.com/larksuite/cli / TestBuildSearchParams

Function TestBuildSearchParams

shortcuts/vc/vc_search_test.go:444–492  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

442}
443
444func TestBuildSearchParams(t *testing.T) {
445 cfg := &core.CliConfig{AppID: "test", AppSecret: "s", Brand: core.BrandFeishu}
446
447 t.Run("defaults", func(t *testing.T) {
448 cmd := &cobra.Command{Use: "test"}
449 cmd.Flags().String("page-token", "", "")
450 cmd.Flags().String("page-size", "", "")
451 runtime := common.TestNewRuntimeContext(cmd, cfg)
452 params := buildSearchParams(runtime)
453 if params["page_size"] != "15" {
454 t.Errorf("page_size = %v, want \"15\"", params["page_size"])
455 }
456 if _, ok := params["page_token"]; ok {
457 t.Error("page_token should be absent when not set")
458 }
459 })
460
461 t.Run("custom page-size and page-token", func(t *testing.T) {
462 cmd := &cobra.Command{Use: "test"}
463 cmd.Flags().String("page-token", "", "")
464 cmd.Flags().String("page-size", "", "")
465 _ = cmd.Flags().Set("page-size", "20")
466 _ = cmd.Flags().Set("page-token", "tok123")
467 runtime := common.TestNewRuntimeContext(cmd, cfg)
468 params := buildSearchParams(runtime)
469 if params["page_size"] != "20" {
470 t.Errorf("page_size = %v, want \"20\"", params["page_size"])
471 }
472 if params["page_token"] != "tok123" {
473 t.Errorf("page_token = %v, want \"tok123\"", params["page_token"])
474 }
475 })
476
477 t.Run("values are scalars not slices", func(t *testing.T) {
478 cmd := &cobra.Command{Use: "test"}
479 cmd.Flags().String("page-token", "", "")
480 cmd.Flags().String("page-size", "", "")
481 _ = cmd.Flags().Set("page-size", "10")
482 _ = cmd.Flags().Set("page-token", "p")
483 runtime := common.TestNewRuntimeContext(cmd, cfg)
484 params := buildSearchParams(runtime)
485 if _, isSlice := params["page_size"].([]string); isSlice {
486 t.Error("page_size must be a scalar string, not []string")
487 }
488 if _, isSlice := params["page_token"].([]string); isSlice {
489 t.Error("page_token must be a scalar string, not []string")
490 }
491 })
492}

Callers

nothing calls this directly

Calls 6

TestNewRuntimeContextFunction · 0.92
buildSearchParamsFunction · 0.70
RunMethod · 0.65
SetMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected