|
|
|
@ -12,6 +12,8 @@ import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/json"
|
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
@ -183,71 +185,61 @@ func TestHTTPClientDownload(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
|
endpoint string
|
|
|
|
|
expectederror string
|
|
|
|
|
expectedError string
|
|
|
|
|
}{
|
|
|
|
|
// case 0
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://status-not-ok.io",
|
|
|
|
|
expectederror: io.ErrUnexpectedEOF.Error(),
|
|
|
|
|
expectedError: io.ErrUnexpectedEOF.Error(),
|
|
|
|
|
},
|
|
|
|
|
// case 1
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://invalid-json-response.io",
|
|
|
|
|
expectederror: "invalid json",
|
|
|
|
|
expectedError: "invalid json",
|
|
|
|
|
},
|
|
|
|
|
// case 2
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://valid-batch-request-download.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
// case 3
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://response-no-objects.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
// case 4
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://unknown-transfer-adapter.io",
|
|
|
|
|
expectederror: "TransferAdapter not found: ",
|
|
|
|
|
expectedError: "TransferAdapter not found: ",
|
|
|
|
|
},
|
|
|
|
|
// case 5
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://error-in-response-objects.io",
|
|
|
|
|
expectederror: "Object not found",
|
|
|
|
|
expectedError: "Object not found",
|
|
|
|
|
},
|
|
|
|
|
// case 6
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://empty-actions-map.io",
|
|
|
|
|
expectederror: "missing action 'download'",
|
|
|
|
|
expectedError: "missing action 'download'",
|
|
|
|
|
},
|
|
|
|
|
// case 7
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://download-actions-map.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
// case 8
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://upload-actions-map.io",
|
|
|
|
|
expectederror: "missing action 'download'",
|
|
|
|
|
expectedError: "missing action 'download'",
|
|
|
|
|
},
|
|
|
|
|
// case 9
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://verify-actions-map.io",
|
|
|
|
|
expectederror: "missing action 'download'",
|
|
|
|
|
expectedError: "missing action 'download'",
|
|
|
|
|
},
|
|
|
|
|
// case 10
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://unknown-actions-map.io",
|
|
|
|
|
expectederror: "missing action 'download'",
|
|
|
|
|
expectedError: "missing action 'download'",
|
|
|
|
|
},
|
|
|
|
|
// case 11
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://legacy-batch-request-download.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for n, c := range cases {
|
|
|
|
|
defer test.MockVariableValue(&setting.LFSClient.BatchOperationConcurrency, 3)()
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
t.Run(c.endpoint, func(t *testing.T) {
|
|
|
|
|
client := &HTTPClient{
|
|
|
|
|
client: hc,
|
|
|
|
|
endpoint: c.endpoint,
|
|
|
|
@ -265,11 +257,12 @@ func TestHTTPClientDownload(t *testing.T) {
|
|
|
|
|
assert.Equal(t, []byte("dummy"), b)
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
if len(c.expectederror) > 0 {
|
|
|
|
|
assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
|
|
|
|
if c.expectedError != "" {
|
|
|
|
|
assert.ErrorContains(t, err, c.expectedError)
|
|
|
|
|
} else {
|
|
|
|
|
assert.NoError(t, err, "case %d", n)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -296,66 +289,57 @@ func TestHTTPClientUpload(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
|
endpoint string
|
|
|
|
|
expectederror string
|
|
|
|
|
expectedError string
|
|
|
|
|
}{
|
|
|
|
|
// case 0
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://status-not-ok.io",
|
|
|
|
|
expectederror: io.ErrUnexpectedEOF.Error(),
|
|
|
|
|
expectedError: io.ErrUnexpectedEOF.Error(),
|
|
|
|
|
},
|
|
|
|
|
// case 1
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://invalid-json-response.io",
|
|
|
|
|
expectederror: "invalid json",
|
|
|
|
|
expectedError: "invalid json",
|
|
|
|
|
},
|
|
|
|
|
// case 2
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://valid-batch-request-upload.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
// case 3
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://response-no-objects.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
// case 4
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://unknown-transfer-adapter.io",
|
|
|
|
|
expectederror: "TransferAdapter not found: ",
|
|
|
|
|
expectedError: "TransferAdapter not found: ",
|
|
|
|
|
},
|
|
|
|
|
// case 5
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://error-in-response-objects.io",
|
|
|
|
|
expectederror: "Object not found",
|
|
|
|
|
expectedError: "Object not found",
|
|
|
|
|
},
|
|
|
|
|
// case 6
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://empty-actions-map.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
// case 7
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://download-actions-map.io",
|
|
|
|
|
expectederror: "missing action 'upload'",
|
|
|
|
|
expectedError: "missing action 'upload'",
|
|
|
|
|
},
|
|
|
|
|
// case 8
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://upload-actions-map.io",
|
|
|
|
|
expectederror: "",
|
|
|
|
|
expectedError: "",
|
|
|
|
|
},
|
|
|
|
|
// case 9
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://verify-actions-map.io",
|
|
|
|
|
expectederror: "missing action 'upload'",
|
|
|
|
|
expectedError: "missing action 'upload'",
|
|
|
|
|
},
|
|
|
|
|
// case 10
|
|
|
|
|
{
|
|
|
|
|
endpoint: "https://unknown-actions-map.io",
|
|
|
|
|
expectederror: "missing action 'upload'",
|
|
|
|
|
expectedError: "missing action 'upload'",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for n, c := range cases {
|
|
|
|
|
defer test.MockVariableValue(&setting.LFSClient.BatchOperationConcurrency, 3)()
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
t.Run(c.endpoint, func(t *testing.T) {
|
|
|
|
|
client := &HTTPClient{
|
|
|
|
|
client: hc,
|
|
|
|
|
endpoint: c.endpoint,
|
|
|
|
@ -367,10 +351,11 @@ func TestHTTPClientUpload(t *testing.T) {
|
|
|
|
|
err := client.Upload(context.Background(), []Pointer{p}, func(p Pointer, objectError error) (io.ReadCloser, error) {
|
|
|
|
|
return io.NopCloser(new(bytes.Buffer)), objectError
|
|
|
|
|
})
|
|
|
|
|
if len(c.expectederror) > 0 {
|
|
|
|
|
assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
|
|
|
|
if c.expectedError != "" {
|
|
|
|
|
assert.ErrorContains(t, err, c.expectedError)
|
|
|
|
|
} else {
|
|
|
|
|
assert.NoError(t, err, "case %d", n)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|