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

Function Test_magicFieldValue

pkg/cmd/workflow/run/run_test.go:153–212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func Test_magicFieldValue(t *testing.T) {
154 f, err := os.CreateTemp(t.TempDir(), "gh-test")
155 if err != nil {
156 t.Fatal(err)
157 }
158 defer f.Close()
159
160 fmt.Fprint(f, "file contents")
161
162 ios, _, _, _ := iostreams.Test()
163
164 type args struct {
165 v string
166 opts RunOptions
167 }
168 tests := []struct {
169 name string
170 args args
171 want interface{}
172 wantErr bool
173 }{
174 {
175 name: "string",
176 args: args{v: "hello"},
177 want: "hello",
178 wantErr: false,
179 },
180 {
181 name: "file",
182 args: args{
183 v: "@" + f.Name(),
184 opts: RunOptions{IO: ios},
185 },
186 want: "file contents",
187 wantErr: false,
188 },
189 {
190 name: "file error",
191 args: args{
192 v: "@",
193 opts: RunOptions{IO: ios},
194 },
195 want: nil,
196 wantErr: true,
197 },
198 }
199 for _, tt := range tests {
200 t.Run(tt.name, func(t *testing.T) {
201 got, err := magicFieldValue(tt.args.v, tt.args.opts)
202 if (err != nil) != tt.wantErr {
203 t.Errorf("magicFieldValue() error = %v, wantErr %v", err, tt.wantErr)
204 return
205 }
206 if tt.wantErr {
207 return
208 }
209 assert.Equal(t, tt.want, got)
210 })

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
EqualMethod · 0.80
magicFieldValueFunction · 0.70
CloseMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected