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

Function Test_uploadWithDelete_retry

pkg/cmd/release/shared/upload_test.go:78–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

76}
77
78func Test_uploadWithDelete_retry(t *testing.T) {
79 retryInterval = 0
80 ctx := context.Background()
81
82 tries := 0
83 client := funcClient(func(req *http.Request) (*http.Response, error) {
84 tries++
85 if tries == 1 {
86 return nil, errors.New("made up exception")
87 } else if tries == 2 {
88 return &http.Response{
89 Request: req,
90 StatusCode: 500,
91 Body: io.NopCloser(bytes.NewBufferString(`{}`)),
92 }, nil
93 }
94 return &http.Response{
95 Request: req,
96 StatusCode: 200,
97 Body: io.NopCloser(bytes.NewBufferString(`{}`)),
98 }, nil
99 })
100 err := uploadWithDelete(ctx, client, "http://example.com/upload", AssetForUpload{
101 Name: "asset",
102 Label: "",
103 Size: 8,
104 Open: func() (io.ReadCloser, error) {
105 return io.NopCloser(bytes.NewBufferString(`somebody`)), nil
106 },
107 MIMEType: "application/octet-stream",
108 })
109 if err != nil {
110 t.Errorf("uploadWithDelete() error: %v", err)
111 }
112 if tries != 3 {
113 t.Errorf("tries = %d, expected %d", tries, 3)
114 }
115}
116
117type funcClient func(*http.Request) (*http.Response, error)
118

Callers

nothing calls this directly

Calls 3

funcClientFuncType · 0.85
uploadWithDeleteFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected