MCPcopy Create free account
hub / github.com/docker/docker-agent / TestCompleteAgentFilename

Function TestCompleteAgentFilename

cmd/root/completion_test.go:13–219  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestCompleteAgentFilename(t *testing.T) {
14 // Note: These tests change working directory so they cannot run in parallel
15
16 tests := []struct {
17 name string
18 setup func(t *testing.T, dir string)
19 toComplete string
20 wantCompletions []string
21 wantNoSpace bool
22 wantNoFileComp bool
23 useRelativePrefix bool // if true, prefix completions with "./"
24 }{
25 {
26 name: "completes yaml files with prefix",
27 setup: func(t *testing.T, dir string) {
28 t.Helper()
29 writeFile(t, dir, "agent.yaml")
30 writeFile(t, dir, "agent2.yaml")
31 writeFile(t, dir, "other.yaml")
32 writeFile(t, dir, "readme.md")
33 },
34 toComplete: "./ag",
35 wantCompletions: []string{"./agent.yaml", "./agent2.yaml"},
36 wantNoSpace: false,
37 wantNoFileComp: true,
38 useRelativePrefix: true,
39 },
40 {
41 name: "completes yml files",
42 setup: func(t *testing.T, dir string) {
43 t.Helper()
44 writeFile(t, dir, "config.yml")
45 writeFile(t, dir, "config.yaml")
46 },
47 toComplete: "./conf",
48 wantCompletions: []string{"./config.yaml", "./config.yml"},
49 wantNoSpace: false,
50 wantNoFileComp: true,
51 useRelativePrefix: true,
52 },
53 {
54 name: "completes directories without trailing space",
55 setup: func(t *testing.T, dir string) {
56 t.Helper()
57 require.NoError(t, os.Mkdir(filepath.Join(dir, "subdir"), 0o755))
58 },
59 toComplete: "./sub",
60 wantCompletions: []string{"./subdir/"},
61 wantNoSpace: true, // directory completion should NOT add space
62 wantNoFileComp: true,
63 useRelativePrefix: true,
64 },
65 {
66 name: "completes both files and directories",
67 setup: func(t *testing.T, dir string) {
68 t.Helper()
69 writeFile(t, dir, "myagent.yaml")
70 require.NoError(t, os.Mkdir(filepath.Join(dir, "mydir"), 0o755))

Callers

nothing calls this directly

Calls 3

completeAgentFilenameFunction · 0.85
writeFileFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected