MCPcopy Index your code
hub / github.com/cli/cli / TestJoin

Function TestJoin

internal/safepaths/absolute_test.go:32–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestJoin(t *testing.T) {
33 t.Parallel()
34
35 tests := []struct {
36 name string
37 base safepaths.Absolute
38 elems []string
39 want safepaths.Absolute
40 wantPathTraversalError bool
41 }{
42 {
43 name: "child of base",
44 base: mustParseAbsolute("/base"),
45 elems: []string{"child"},
46 want: mustParseAbsolute("/base/child"),
47 },
48 {
49 name: "grandchild of base",
50 base: mustParseAbsolute("/base"),
51 elems: []string{"child", "grandchild"},
52 want: mustParseAbsolute("/base/child/grandchild"),
53 },
54 {
55 name: "relative parent of base",
56 base: mustParseAbsolute("/base"),
57 elems: []string{".."},
58 wantPathTraversalError: true,
59 },
60 {
61 name: "relative grandparent of base",
62 base: mustParseAbsolute("/base"),
63 elems: []string{"..", ".."},
64 wantPathTraversalError: true,
65 },
66 {
67 name: "relative current dir",
68 base: mustParseAbsolute("/base"),
69 elems: []string{"."},
70 want: mustParseAbsolute("/base"),
71 },
72 {
73 name: "subpath via relative parent",
74 base: mustParseAbsolute("/child"),
75 elems: []string{"..", "child"},
76 want: mustParseAbsolute("/child"),
77 },
78 {
79 name: "empty string",
80 base: mustParseAbsolute("/base"),
81 elems: []string{""},
82 want: mustParseAbsolute("/base"),
83 },
84 }
85 for _, tt := range tests {
86 t.Run(tt.name, func(t *testing.T) {
87 t.Parallel()
88 joinedPath, err := tt.base.Join(tt.elems...)
89 if tt.wantPathTraversalError {

Callers

nothing calls this directly

Calls 4

mustParseAbsoluteFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected