MCPcopy Create free account
hub / github.com/cli/cli / TestFlagUserAssets

Function TestFlagUserAssets

internal/attachments/flags_test.go:91–280  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestFlagUserAssets(t *testing.T) {
92 tests := []struct {
93 name string
94 setup func(t *testing.T)
95 input string
96 wantPaths []string
97 wantAlts []string
98 wantErr string
99 // wantErrIs covers an error whose text the operating system words
100 // differently, so the assertion cannot be on the message.
101 wantErrIs error
102 }{
103 {
104 name: "not passed",
105 input: "",
106 },
107 {
108 name: "one file",
109 input: "--attach ./shot.png",
110 wantPaths: []string{"./shot.png"},
111 },
112 {
113 name: "a filename containing a hash stays whole",
114 input: "--attach './shot#dark.png'",
115 wantPaths: []string{"./shot#dark.png"},
116 wantAlts: []string{"shot#dark"},
117 },
118 {
119 name: "alt text can contain a hash",
120 input: "--attach './caption.png#first#second'",
121 wantPaths: []string{"./caption.png"},
122 wantAlts: []string{"first#second"},
123 },
124 {
125 name: "the longest existing path wins",
126 input: "--attach './shot#dark.png#first.png#second'",
127 wantPaths: []string{"./shot#dark.png#first.png"},
128 wantAlts: []string{"second"},
129 },
130 {
131 name: "a missing path falls back at the last hash",
132 input: "--attach './gone.png#caption'",
133 wantErr: "./gone.png: ",
134 wantErrIs: fs.ErrNotExist,
135 },
136 {
137 name: "several files, in the order written",
138 input: "--attach ./b.png --attach ./a.png",
139 wantPaths: []string{"./b.png", "./a.png"},
140 },
141 {
142 name: "too many attachments are rejected before filesystem validation",
143 input: strings.Repeat("--attach ./missing.txt ", maxAttachments+1),
144 wantErr: "`--attach` accepts at most 50 values per command",
145 },
146 {
147 name: "a file that does not exist",
148 input: "--attach ./gone.png",

Callers

nothing calls this directly

Calls 9

attachCmdFunction · 0.85
NewTestAssetsFunction · 0.85
UserAssetsMethod · 0.80
EqualMethod · 0.80
LinkMethod · 0.65
RunMethod · 0.65
PathMethod · 0.65
getAssetMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected