Fix CI tests (#579)

- `master` -> `main`, due to https://github.com/go-gitea/gitea/pull/19354
- Fix incorrect variable being passed into assert in `TestPull`.
- Fix `createTestRepo` to only delete existing TestRepo if the result's repo wasn't redirected(e.g. due to being transferred or renamed). Fixes the error in TransferRepo.
- Remove a check for tag verfication, for some developers this will always fail due to local git configs forcing signing on tags.

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/579
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-committed-by: Gusted <williamzijl7@hotmail.com>
This commit is contained in:
Gusted 2022-04-22 15:52:45 +08:00 committed by Lunny Xiao
parent a56a62a4df
commit 603e4358f8
9 changed files with 74 additions and 67 deletions

View file

@ -59,13 +59,13 @@ func editIssues(t *testing.T, c *Client) {
Title: "Edited",
Body: OptionalString("123 test and go"),
State: &state,
Ref: OptionalString("master"),
Ref: OptionalString("main"),
})
assert.NoError(t, err)
assert.EqualValues(t, issue.ID, issueNew.ID)
assert.EqualValues(t, "123 test and go", issueNew.Body)
assert.EqualValues(t, "Edited", issueNew.Title)
assert.EqualValues(t, "master", issueNew.Ref)
assert.EqualValues(t, "main", issueNew.Ref)
}
func listIssues(t *testing.T, c *Client) {

View file

@ -15,7 +15,7 @@ func TestPullReview(t *testing.T) {
log.Println("== TestPullReview ==")
c := newTestClient()
var repoName = "Reviews"
repoName := "Reviews"
repo, pull, submitter, reviewer, success := preparePullReviewTest(t, c, repoName)
if !success {
return
@ -49,11 +49,12 @@ func TestPullReview(t *testing.T) {
r3, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
State: ReviewStateApproved,
Body: "lgtm",
Comments: []CreatePullReviewComment{{
Path: "WOW-file",
Body: "no better name - really?",
NewLineNum: 1,
},
Comments: []CreatePullReviewComment{
{
Path: "WOW-file",
Body: "no better name - really?",
NewLineNum: 1,
},
},
})
assert.NoError(t, err)
@ -87,22 +88,24 @@ func TestPullReview(t *testing.T) {
c.SetSudo("")
r4, resp, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
Body: "...",
Comments: []CreatePullReviewComment{{
Path: "WOW-file",
Body: "its ok",
NewLineNum: 1,
},
Comments: []CreatePullReviewComment{
{
Path: "WOW-file",
Body: "its ok",
NewLineNum: 1,
},
},
})
assert.NoError(t, err)
assert.NotNil(t, resp)
r5, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
Body: "...",
Comments: []CreatePullReviewComment{{
Path: "WOW-file",
Body: "hehe and here it is",
NewLineNum: 3,
},
Comments: []CreatePullReviewComment{
{
Path: "WOW-file",
Body: "hehe and here it is",
NewLineNum: 3,
},
},
})
assert.NoError(t, err)
@ -200,7 +203,7 @@ func preparePullReviewTest(t *testing.T, c *Client, repoName string) (*Repositor
Content: "QSBuZXcgRmlsZQoKYW5kIHNvbWUgbGluZXMK",
FileOptions: FileOptions{
Message: "creat a new file",
BranchName: "master",
BranchName: "main",
NewBranchName: "new_file",
},
})
@ -210,7 +213,7 @@ func preparePullReviewTest(t *testing.T, c *Client, repoName string) (*Repositor
}
pull, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
Base: "master",
Base: "main",
Head: "new_file",
Title: "Creat a NewFile",
})

View file

@ -17,8 +17,8 @@ func TestPull(t *testing.T) {
user, _, err := c.GetMyUserInfo()
assert.NoError(t, err)
var repoName = "repo_pull_test"
var forkOrg = "ForkOrg"
repoName := "repo_pull_test"
forkOrg := "ForkOrg"
if !preparePullTest(t, c, repoName, forkOrg) {
return
}
@ -29,7 +29,7 @@ func TestPull(t *testing.T) {
assert.Len(t, pulls, 0)
pullUpdateFile, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
Base: "master",
Base: "main",
Head: forkOrg + ":overwrite_licence",
Title: "overwrite a file",
})
@ -37,7 +37,7 @@ func TestPull(t *testing.T) {
assert.NotNil(t, pullUpdateFile)
pullNewFile, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
Base: "master",
Base: "main",
Head: forkOrg + ":new_file",
Title: "create a file",
})
@ -45,7 +45,7 @@ func TestPull(t *testing.T) {
assert.NotNil(t, pullNewFile)
pullConflict, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
Base: "master",
Base: "main",
Head: forkOrg + ":will_conflict",
Title: "this pull will conflict",
})
@ -97,8 +97,8 @@ func TestPull(t *testing.T) {
// test conflict pull
pr, _, err = c.GetPullRequest(user.UserName, repoName, pullConflict.Index)
assert.NoError(t, err)
assert.False(t, pullConflict.HasMerged)
assert.False(t, pullConflict.Mergeable)
assert.False(t, pr.HasMerged)
assert.False(t, pr.Mergeable)
merged, _, err = c.MergePullRequest(user.UserName, repoName, pullConflict.Index, MergePullRequestOption{
Style: MergeStyleMerge,
Title: "pullConflict",
@ -145,18 +145,18 @@ func preparePullTest(t *testing.T, c *Client, repoName, forkOrg string) bool {
assert.NoError(t, err)
assert.NotNil(t, forkRepo)
masterLicence, _, err := c.GetContents(forkRepo.Owner.UserName, forkRepo.Name, "master", "LICENSE")
if !assert.NoError(t, err) || !assert.NotNil(t, masterLicence) {
mainLicense, _, err := c.GetContents(forkRepo.Owner.UserName, forkRepo.Name, "main", "LICENSE")
if !assert.NoError(t, err) || !assert.NotNil(t, mainLicense) {
return false
}
updatedFile, _, err := c.UpdateFile(forkRepo.Owner.UserName, forkRepo.Name, "LICENSE", UpdateFileOptions{
FileOptions: FileOptions{
Message: "Overwrite",
BranchName: "master",
BranchName: "main",
NewBranchName: "overwrite_licence",
},
SHA: masterLicence.SHA,
SHA: mainLicense.SHA,
Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=",
})
if !assert.NoError(t, err) || !assert.NotNil(t, updatedFile) {
@ -167,7 +167,7 @@ func preparePullTest(t *testing.T, c *Client, repoName, forkOrg string) bool {
Content: "QSBuZXcgRmlsZQo=",
FileOptions: FileOptions{
Message: "creat a new file",
BranchName: "master",
BranchName: "main",
NewBranchName: "new_file",
},
})
@ -179,7 +179,7 @@ func preparePullTest(t *testing.T, c *Client, repoName, forkOrg string) bool {
Content: "U3RhcnQgQ29uZmxpY3QK",
FileOptions: FileOptions{
Message: "Start Conflict",
BranchName: "master",
BranchName: "main",
},
})
if !assert.NoError(t, err) || !assert.NotNil(t, conflictFile1) {
@ -190,7 +190,7 @@ func preparePullTest(t *testing.T, c *Client, repoName, forkOrg string) bool {
Content: "V2lsbEhhdmUgQ29uZmxpY3QK",
FileOptions: FileOptions{
Message: "creat a new file witch will conflict",
BranchName: "master",
BranchName: "main",
NewBranchName: "will_conflict",
},
})

View file

@ -26,7 +26,7 @@ func TestRelease(t *testing.T) {
// CreateRelease
r, _, err := c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
TagName: "awesome",
Target: "master",
Target: "main",
Title: "Release 1",
Note: "yes it's awesome",
IsDraft: true,
@ -38,7 +38,7 @@ func TestRelease(t *testing.T) {
assert.EqualValues(t, true, r.IsDraft)
assert.EqualValues(t, "Release 1", r.Title)
assert.EqualValues(t, fmt.Sprintf("%s/api/v1/repos/%s/releases/%d", c.url, repo.FullName, r.ID), r.URL)
assert.EqualValues(t, "master", r.Target)
assert.EqualValues(t, "main", r.Target)
assert.EqualValues(t, "yes it's awesome", r.Note)
assert.EqualValues(t, c.username, r.Publisher.UserName)
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
@ -85,7 +85,7 @@ func TestRelease(t *testing.T) {
// CreateRelease
_, _, err = c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
TagName: "aNewReleaseTag",
Target: "master",
Target: "main",
Title: "Title of aNewReleaseTag",
})
assert.NoError(t, err)

View file

@ -14,7 +14,7 @@ import (
func TestRepoBranches(t *testing.T) {
log.Println("== TestRepoBranches ==")
c := newTestClient()
var repoName = "branches"
repoName := "branches"
repo := prepareBranchTest(t, c, repoName)
if repo == nil {
@ -25,7 +25,7 @@ func TestRepoBranches(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, bl, 3)
assert.EqualValues(t, "feature", bl[0].Name)
assert.EqualValues(t, "master", bl[1].Name)
assert.EqualValues(t, "main", bl[1].Name)
assert.EqualValues(t, "update", bl[2].Name)
b, _, err := c.GetRepoBranch(repo.Owner.UserName, repo.Name, "update")
@ -33,7 +33,7 @@ func TestRepoBranches(t *testing.T) {
assert.EqualValues(t, bl[2].Commit.ID, b.Commit.ID)
assert.EqualValues(t, bl[2].Commit.Added, b.Commit.Added)
s, _, err := c.DeleteRepoBranch(repo.Owner.UserName, repo.Name, "master")
s, _, err := c.DeleteRepoBranch(repo.Owner.UserName, repo.Name, "main")
assert.NoError(t, err)
assert.False(t, s)
s, _, err = c.DeleteRepoBranch(repo.Owner.UserName, repo.Name, "feature")
@ -59,7 +59,7 @@ func TestRepoBranches(t *testing.T) {
func TestRepoBranchProtection(t *testing.T) {
log.Println("== TestRepoBranchProtection ==")
c := newTestClient()
var repoName = "BranchProtection"
repoName := "BranchProtection"
repo := prepareBranchTest(t, c, repoName)
if repo == nil {
@ -74,7 +74,7 @@ func TestRepoBranchProtection(t *testing.T) {
// CreateBranchProtection
bp, _, err := c.CreateBranchProtection(repo.Owner.UserName, repo.Name, CreateBranchProtectionOption{
BranchName: "master",
BranchName: "main",
EnablePush: true,
EnablePushWhitelist: true,
PushWhitelistUsernames: []string{"test01"},
@ -83,7 +83,7 @@ func TestRepoBranchProtection(t *testing.T) {
BlockOnOutdatedBranch: true,
})
assert.NoError(t, err)
assert.EqualValues(t, "master", bp.BranchName)
assert.EqualValues(t, "main", bp.BranchName)
assert.EqualValues(t, false, bp.EnableStatusCheck)
assert.EqualValues(t, true, bp.EnablePush)
assert.EqualValues(t, true, bp.EnablePushWhitelist)
@ -136,18 +136,18 @@ func prepareBranchTest(t *testing.T, c *Client, repoName string) *Repository {
return nil
}
masterLicence, _, err := c.GetContents(origRepo.Owner.UserName, origRepo.Name, "master", "README.md")
if !assert.NoError(t, err) || !assert.NotNil(t, masterLicence) {
mainLicense, _, err := c.GetContents(origRepo.Owner.UserName, origRepo.Name, "main", "README.md")
if !assert.NoError(t, err) || !assert.NotNil(t, mainLicense) {
return nil
}
updatedFile, _, err := c.UpdateFile(origRepo.Owner.UserName, origRepo.Name, "README.md", UpdateFileOptions{
FileOptions: FileOptions{
Message: "update it",
BranchName: "master",
BranchName: "main",
NewBranchName: "update",
},
SHA: masterLicence.SHA,
SHA: mainLicense.SHA,
Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=",
})
if !assert.NoError(t, err) || !assert.NotNil(t, updatedFile) {
@ -158,7 +158,7 @@ func prepareBranchTest(t *testing.T, c *Client, repoName string) *Repository {
Content: "QSBuZXcgRmlsZQo=",
FileOptions: FileOptions{
Message: "creat a new file",
BranchName: "master",
BranchName: "main",
NewBranchName: "feature",
},
})

View file

@ -21,7 +21,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, repo)
raw, _, err := c.GetFile(repo.Owner.UserName, repo.Name, "master", "README.md")
raw, _, err := c.GetFile(repo.Owner.UserName, repo.Name, "main", "README.md")
assert.NoError(t, err)
assert.EqualValues(t, "IyBDaGFuZ2VGaWxlcwoKQSB0ZXN0IFJlcG86IENoYW5nZUZpbGVz", base64.StdEncoding.EncodeToString(raw))
@ -33,7 +33,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
Content: "ZmlsZUEK",
})
assert.NoError(t, err)
raw, _, _ = c.GetFile(repo.Owner.UserName, repo.Name, "master", testFileName)
raw, _, _ = c.GetFile(repo.Owner.UserName, repo.Name, "main", testFileName)
assert.EqualValues(t, "ZmlsZUEK", base64.StdEncoding.EncodeToString(raw))
updatedFile, _, err := c.UpdateFile(repo.Owner.UserName, repo.Name, testFileName, UpdateFileOptions{
@ -46,7 +46,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, updatedFile)
file, _, err := c.GetContents(repo.Owner.UserName, repo.Name, "master", testFileName)
file, _, err := c.GetContents(repo.Owner.UserName, repo.Name, "main", testFileName)
assert.NoError(t, err)
assert.EqualValues(t, updatedFile.Content.SHA, file.SHA)
assert.EqualValues(t, &updatedFile.Content.Content, &file.Content)
@ -58,7 +58,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
SHA: updatedFile.Content.SHA,
})
assert.NoError(t, err)
_, resp, err := c.GetFile(repo.Owner.UserName, repo.Name, "master", testFileName)
_, resp, err := c.GetFile(repo.Owner.UserName, repo.Name, "main", testFileName)
assert.Error(t, err)
assert.EqualValues(t, 404, resp.StatusCode)
@ -69,7 +69,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
updatedFile, _, err = c.UpdateFile(repo.Owner.UserName, repo.Name, "LICENSE", UpdateFileOptions{
FileOptions: FileOptions{
Message: "Overwrite",
BranchName: "master",
BranchName: "main",
NewBranchName: "overwrite-a+/&licence",
},
SHA: licence.SHA,

View file

@ -23,12 +23,12 @@ func TestTags(t *testing.T) {
cTag, resp, err := c.CreateTag(repo.Owner.UserName, repo.Name, CreateTagOption{
TagName: "tag1",
Message: cTagMSG,
Target: "master",
Target: "main",
})
assert.NoError(t, err)
assert.EqualValues(t, 201, resp.StatusCode)
assert.EqualValues(t, cTagMSG, cTag.Message)
assert.EqualValues(t, fmt.Sprintf("%s/test01/TestTags/archive/tag1.zip", c.url), cTag.ZipballURL)
assert.EqualValues(t, fmt.Sprintf("%s/%s/TestTags/archive/tag1.zip", c.url, c.username), cTag.ZipballURL)
tags, _, err := c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{})
assert.NoError(t, err)
@ -44,9 +44,8 @@ func TestTags(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, cTag.Name, aTag.Tag)
assert.EqualValues(t, cTag.ID, aTag.SHA)
assert.EqualValues(t, fmt.Sprintf("%s/api/v1/repos/test01/TestTags/git/tags/%s", c.url, cTag.ID), aTag.URL)
assert.EqualValues(t, fmt.Sprintf("%s/api/v1/repos/%s/TestTags/git/tags/%s", c.url, c.username, cTag.ID), aTag.URL)
assert.EqualValues(t, cTag.Message+"\n", aTag.Message)
assert.EqualValues(t, false, aTag.Verification.Verified)
assert.EqualValues(t, "commit", aTag.Object.Type)
// DeleteReleaseTag

View file

@ -20,7 +20,7 @@ func TestCreateRepo(t *testing.T) {
user, _, err := c.GetMyUserInfo()
assert.NoError(t, err)
var repoName = "test1"
repoName := "test1"
_, _, err = c.GetRepo(user.UserName, repoName)
if err != nil {
repo, _, err := c.CreateRepo(CreateRepoOption{
@ -138,7 +138,7 @@ func TestGetArchive(t *testing.T) {
c := newTestClient()
repo, _ := createTestRepo(t, "ToDownload", c)
time.Sleep(time.Second / 2)
archive, _, err := c.GetArchive(repo.Owner.UserName, repo.Name, "master", ZipArchive)
archive, _, err := c.GetArchive(repo.Owner.UserName, repo.Name, "main", ZipArchive)
assert.NoError(t, err)
assert.True(t, len(archive) > 1500 && len(archive) < 1700)
}
@ -148,7 +148,7 @@ func TestGetArchiveReader(t *testing.T) {
c := newTestClient()
repo, _ := createTestRepo(t, "ToDownload", c)
time.Sleep(time.Second / 2)
r, _, err := c.GetArchiveReader(repo.Owner.UserName, repo.Name, "master", ZipArchive)
r, _, err := c.GetArchiveReader(repo.Owner.UserName, repo.Name, "main", ZipArchive)
assert.NoError(t, err)
defer r.Close()
@ -177,11 +177,15 @@ func TestGetRepoByID(t *testing.T) {
func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) {
user, _, uErr := c.GetMyUserInfo()
assert.NoError(t, uErr)
_, _, err := c.GetRepo(user.UserName, name)
if err == nil {
repo, _, err := c.GetRepo(user.UserName, name)
// We need to check that the received repo is not a
// redirected one, it could be the case that gitea redirect us
// to a new repo(because it e.g. was transferred or renamed).
if err == nil && repo.Owner.UserName == user.UserName {
_, _ = c.DeleteRepo(user.UserName, name)
}
repo, _, err := c.CreateRepo(CreateRepoOption{
repo, _, err = c.CreateRepo(CreateRepoOption{
Name: name,
Description: "A test Repo: " + name,
AutoInit: true,

View file

@ -20,20 +20,21 @@ func TestRepoTransfer(t *testing.T) {
repo, err := createTestRepo(t, "ToMove", c)
assert.NoError(t, err)
newRepo, _, err := c.TransferRepo(repo.Owner.UserName, repo.Name, TransferRepoOption{NewOwner: org.UserName})
newRepo, _, err := c.TransferRepo(c.username, repo.Name, TransferRepoOption{NewOwner: org.UserName})
assert.NoError(t, err) // admin transfer repository will execute immediately but not set as pendding.
assert.NotNil(t, newRepo)
assert.EqualValues(t, "ToMove", newRepo.Name)
repo, err = createTestRepo(t, "ToMove", c)
assert.NoError(t, err)
_, _, err = c.TransferRepo(repo.Owner.UserName, repo.Name, TransferRepoOption{NewOwner: org.UserName})
assert.Error(t, err, err.Error()) // org.UserName/repo.Name has exist
_, resp, err := c.TransferRepo(c.username, repo.Name, TransferRepoOption{NewOwner: org.UserName})
assert.EqualValues(t, 422, resp.StatusCode)
assert.Error(t, err)
_, err = c.DeleteRepo(repo.Owner.UserName, repo.Name)
assert.NoError(t, err)
_, err = c.DeleteRepo(newRepo.Owner.UserName, newRepo.Name)
assert.Error(t, err)
assert.NoError(t, err)
_, err = c.DeleteOrg(org.UserName)
assert.NoError(t, err)
}