forked from kevadesu/forgejo
Merge pull request '[gitea] week 2024-24 cherry pick (gitea/main -> forgejo)' (#4083) from earl-warren/wcp/2024-24 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4083 Reviewed-by: twenty-panda <twenty-panda@noreply.codeberg.org>
This commit is contained in:
commit
df373c9f7e
53 changed files with 532 additions and 226 deletions
|
@ -431,22 +431,33 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
|||
|
||||
t.Run("SearchService", func(t *testing.T) {
|
||||
cases := []struct {
|
||||
Query string
|
||||
Skip int
|
||||
Take int
|
||||
ExpectedTotal int64
|
||||
ExpectedResults int
|
||||
Query string
|
||||
Skip int
|
||||
Take int
|
||||
ExpectedTotal int64
|
||||
ExpectedResults int
|
||||
ExpectedExactMatch bool
|
||||
}{
|
||||
{"", 0, 0, 1, 1},
|
||||
{"", 0, 10, 1, 1},
|
||||
{"gitea", 0, 10, 0, 0},
|
||||
{"test", 0, 10, 1, 1},
|
||||
{"test", 1, 10, 1, 0},
|
||||
{"", 0, 0, 4, 4, false},
|
||||
{"", 0, 10, 4, 4, false},
|
||||
{"gitea", 0, 10, 0, 0, false},
|
||||
{"test", 0, 10, 1, 1, false},
|
||||
{"test", 1, 10, 1, 0, false},
|
||||
{"almost.similar", 0, 0, 3, 3, true},
|
||||
}
|
||||
|
||||
req := NewRequestWithBody(t, "PUT", url, createPackage(packageName, "1.0.99")).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
fakePackages := []string{
|
||||
packageName,
|
||||
"almost.similar.dependency",
|
||||
"almost.similar",
|
||||
"almost.similar.dependant",
|
||||
}
|
||||
|
||||
for _, fakePackageName := range fakePackages {
|
||||
req := NewRequestWithBody(t, "PUT", url, createPackage(fakePackageName, "1.0.99")).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
}
|
||||
|
||||
t.Run("v2", func(t *testing.T) {
|
||||
t.Run("Search()", func(t *testing.T) {
|
||||
|
@ -493,6 +504,63 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("Packages()", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
t.Run("substringof", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
for i, c := range cases {
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/Packages()?$filter=substringof('%s',tolower(Id))&$skip=%d&$top=%d", url, c.Query, c.Skip, c.Take)).
|
||||
AddBasicAuth(user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var result FeedResponse
|
||||
decodeXML(t, resp, &result)
|
||||
|
||||
assert.Equal(t, c.ExpectedTotal, result.Count, "case %d: unexpected total hits", i)
|
||||
assert.Len(t, result.Entries, c.ExpectedResults, "case %d: unexpected result count", i)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/Packages()/$count?$filter=substringof('%s',tolower(Id))&$skip=%d&$top=%d", url, c.Query, c.Skip, c.Take)).
|
||||
AddBasicAuth(user.Name)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
assert.Equal(t, strconv.FormatInt(c.ExpectedTotal, 10), resp.Body.String(), "case %d: unexpected total hits", i)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("IdEq", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
for i, c := range cases {
|
||||
if c.Query == "" {
|
||||
// Ignore the `tolower(Id) eq ''` as it's unlikely to happen
|
||||
continue
|
||||
}
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/Packages()?$filter=(tolower(Id) eq '%s')&$skip=%d&$top=%d", url, c.Query, c.Skip, c.Take)).
|
||||
AddBasicAuth(user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var result FeedResponse
|
||||
decodeXML(t, resp, &result)
|
||||
|
||||
expectedCount := 0
|
||||
if c.ExpectedExactMatch {
|
||||
expectedCount = 1
|
||||
}
|
||||
|
||||
assert.Equal(t, int64(expectedCount), result.Count, "case %d: unexpected total hits", i)
|
||||
assert.Len(t, result.Entries, expectedCount, "case %d: unexpected result count", i)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/Packages()/$count?$filter=(tolower(Id) eq '%s')&$skip=%d&$top=%d", url, c.Query, c.Skip, c.Take)).
|
||||
AddBasicAuth(user.Name)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
assert.Equal(t, strconv.FormatInt(int64(expectedCount), 10), resp.Body.String(), "case %d: unexpected total hits", i)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Next", func(t *testing.T) {
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/Search()?searchTerm='test'&$skip=0&$top=1", url)).
|
||||
AddBasicAuth(user.Name)
|
||||
|
@ -550,9 +618,11 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
|||
})
|
||||
})
|
||||
|
||||
req = NewRequest(t, "DELETE", fmt.Sprintf("%s/%s/%s", url, packageName, "1.0.99")).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
for _, fakePackageName := range fakePackages {
|
||||
req := NewRequest(t, "DELETE", fmt.Sprintf("%s/%s/%s", url, fakePackageName, "1.0.99")).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("RegistrationService", func(t *testing.T) {
|
||||
|
|
|
@ -42,7 +42,7 @@ func TestAPIRepoTags(t *testing.T) {
|
|||
assert.Equal(t, setting.AppURL+"user2/repo1/archive/v1.1.zip", tags[0].ZipballURL)
|
||||
assert.Equal(t, setting.AppURL+"user2/repo1/archive/v1.1.tar.gz", tags[0].TarballURL)
|
||||
|
||||
newTag := createNewTagUsingAPI(t, session, token, user.Name, repoName, "gitea/22", "", "nice!\nand some text")
|
||||
newTag := createNewTagUsingAPI(t, token, user.Name, repoName, "gitea/22", "", "nice!\nand some text")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &tags)
|
||||
assert.Len(t, tags, 2)
|
||||
|
@ -72,7 +72,7 @@ func TestAPIRepoTags(t *testing.T) {
|
|||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func createNewTagUsingAPI(t *testing.T, session *TestSession, token, ownerName, repoName, name, target, msg string) *api.Tag {
|
||||
func createNewTagUsingAPI(t *testing.T, token, ownerName, repoName, name, target, msg string) *api.Tag {
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/tags", ownerName, repoName)
|
||||
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateTagOption{
|
||||
TagName: name,
|
||||
|
@ -96,7 +96,7 @@ func TestAPIGetTagArchiveDownloadCount(t *testing.T) {
|
|||
repoName := "repo1"
|
||||
tagName := "TagDownloadCount"
|
||||
|
||||
createNewTagUsingAPI(t, session, token, user.Name, repoName, tagName, "", "")
|
||||
createNewTagUsingAPI(t, token, user.Name, repoName, tagName, "", "")
|
||||
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/tags/%s?token=%s", user.Name, repoName, tagName, token)
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ func (c *compareDump) assertLoadFiles(beforeFilename, afterFilename string, t re
|
|||
//
|
||||
// Given []Something{} create afterPtr, beforePtr []*Something{}
|
||||
//
|
||||
sliceType := reflect.SliceOf(reflect.PtrTo(t.Elem()))
|
||||
sliceType := reflect.SliceOf(reflect.PointerTo(t.Elem()))
|
||||
beforeSlice := reflect.MakeSlice(sliceType, 0, 10)
|
||||
beforePtr = reflect.New(beforeSlice.Type())
|
||||
beforePtr.Elem().Set(beforeSlice)
|
||||
|
|
|
@ -36,7 +36,7 @@ func TestGPGGit(t *testing.T) {
|
|||
defer os.Setenv("GNUPGHOME", oldGNUPGHome)
|
||||
|
||||
// Need to create a root key
|
||||
rootKeyPair, err := importTestingKey(tmpDir, "gitea", "gitea@fake.local")
|
||||
rootKeyPair, err := importTestingKey()
|
||||
if !assert.NoError(t, err, "importTestingKey") {
|
||||
return
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ func TestGPGGit(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func crudActionCreateFile(t *testing.T, ctx APITestContext, user *user_model.User, from, to, path string, callback ...func(*testing.T, api.FileResponse)) func(*testing.T) {
|
||||
func crudActionCreateFile(_ *testing.T, ctx APITestContext, user *user_model.User, from, to, path string, callback ...func(*testing.T, api.FileResponse)) func(*testing.T) {
|
||||
return doAPICreateFile(ctx, path, &api.CreateFileOptions{
|
||||
FileOptions: api.FileOptions{
|
||||
BranchName: from,
|
||||
|
@ -282,7 +282,7 @@ func crudActionCreateFile(t *testing.T, ctx APITestContext, user *user_model.Use
|
|||
}, callback...)
|
||||
}
|
||||
|
||||
func importTestingKey(tmpDir, name, email string) (*openpgp.Entity, error) {
|
||||
func importTestingKey() (*openpgp.Entity, error) {
|
||||
if _, _, err := process.GetManager().Exec("gpg --import tests/integration/private-testing.key", "gpg", "--import", "tests/integration/private-testing.key"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue