MCPcopy Create free account
hub / github.com/celer-pkg/celer / TestSearchCmd_Completion

Function TestSearchCmd_Completion

cmds/cmd_search_test.go:329–394  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

327}
328
329func TestSearchCmd_Completion(t *testing.T) {
330 // Cleanup.
331 dirs.RemoveAllForTest()
332
333 // Check error.
334 var check = func(err error) {
335 t.Helper()
336 if err != nil {
337 t.Fatal(err)
338 }
339 }
340
341 // Init celer.
342 celer := configs.NewCeler()
343 check(celer.Init())
344 check(celer.CloneConf(test_conf_repo_url, test_conf_repo_branch, true))
345 check(celer.SetBuildType("Release"))
346
347 searchCmd := searchCmd{celer: celer}
348 cmd := searchCmd.Command(celer)
349
350 t.Run("completion for ports", func(t *testing.T) {
351 suggestions, directive := searchCmd.completion(cmd, []string{}, "zlib")
352 if directive != cobra.ShellCompDirectiveNoFileComp {
353 t.Errorf("Expected directive NoFileComp, got %v", directive)
354 }
355
356 // Should get suggestions starting with "zlib"
357 if len(suggestions) > 0 {
358 for _, suggestion := range suggestions {
359 if !strings.HasPrefix(suggestion, "zlib") {
360 t.Errorf("Suggestion %s should start with 'zlib'", suggestion)
361 }
362 }
363 }
364 })
365
366 t.Run("completion with empty prefix", func(t *testing.T) {
367 suggestions, _ := searchCmd.completion(cmd, []string{}, "")
368
369 // Should return all available ports.
370 if len(suggestions) == 0 {
371 t.Log("No suggestions found (may be acceptable if no ports exist)")
372 }
373 })
374
375 t.Run("completion from project ports", func(t *testing.T) {
376 // Set a project.
377 check(celer.SetProject("project_test_01"))
378
379 // Create a test project-specific port for completion.
380 projectPortDir := filepath.Join(dirs.ConfProjectsDir, "project_test_01", "mylib", "2.0.0")
381 check(os.MkdirAll(projectPortDir, os.ModePerm))
382
383 portTomlPath := filepath.Join(projectPortDir, "port.toml")
384 check(os.WriteFile(portTomlPath, []byte("[package]\nname = \"mylib\"\nversion = \"2.0.0\"\n"), 0644))
385
386 suggestions, _ := searchCmd.completion(cmd, []string{}, "mylib")

Callers

nothing calls this directly

Calls 12

InitMethod · 0.95
CloneConfMethod · 0.95
SetBuildTypeMethod · 0.95
CommandMethod · 0.95
completionMethod · 0.95
SetProjectMethod · 0.95
RemoveAllForTestFunction · 0.92
NewCelerFunction · 0.92
checkFunction · 0.85
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected