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

Function Test_uploadWithDelete_retry

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

Source from the content-addressed store, hash-verified

78}
79
80func Test_uploadWithDelete_retry(t *testing.T) {
81 retryInterval = 0
82 ctx := context.Background()
83
84 tries := 0
85 client := &http.Client{Transport: funcTripper(func(req *http.Request) (*http.Response, error) {
86 tries++
87 if tries == 1 {
88 return nil, errors.New("made up exception")
89 } else if tries == 2 {
90 return &http.Response{
91 Request: req,
92 StatusCode: 500,
93 Body: io.NopCloser(bytes.NewBufferString(`{}`)),
94 }, nil
95 }
96 return &http.Response{
97 Request: req,
98 StatusCode: 200,
99 Body: io.NopCloser(bytes.NewBufferString(`{}`)),
100 }, nil
101 })}
102 err := uploadWithDelete(ctx, client, "github.com", safeurl.NewImmutableSafeURL("http://example.com/upload"), AssetForUpload{
103 Name: "asset",
104 Label: "",
105 Size: 8,
106 Open: func() (io.ReadCloser, error) {
107 return io.NopCloser(bytes.NewBufferString(`somebody`)), nil
108 },
109 MIMEType: "application/octet-stream",
110 })
111 if err != nil {
112 t.Errorf("uploadWithDelete() error: %v", err)
113 }
114 if tries != 3 {
115 t.Errorf("tries = %d, expected %d", tries, 3)
116 }
117}
118
119// funcTripper drives uploadWithDelete from a plain function. It is a RoundTripper rather than
120// a Do-er because the upload path takes a concrete *http.Client, which is what api.Client needs.

Callers

nothing calls this directly

Calls 4

NewImmutableSafeURLFunction · 0.92
uploadWithDeleteFunction · 0.85
funcTripperFuncType · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected