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:
parent
a56a62a4df
commit
603e4358f8
9 changed files with 74 additions and 67 deletions
|
@ -59,13 +59,13 @@ func editIssues(t *testing.T, c *Client) {
|
||||||
Title: "Edited",
|
Title: "Edited",
|
||||||
Body: OptionalString("123 test and go"),
|
Body: OptionalString("123 test and go"),
|
||||||
State: &state,
|
State: &state,
|
||||||
Ref: OptionalString("master"),
|
Ref: OptionalString("main"),
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, issue.ID, issueNew.ID)
|
assert.EqualValues(t, issue.ID, issueNew.ID)
|
||||||
assert.EqualValues(t, "123 test and go", issueNew.Body)
|
assert.EqualValues(t, "123 test and go", issueNew.Body)
|
||||||
assert.EqualValues(t, "Edited", issueNew.Title)
|
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) {
|
func listIssues(t *testing.T, c *Client) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestPullReview(t *testing.T) {
|
||||||
log.Println("== TestPullReview ==")
|
log.Println("== TestPullReview ==")
|
||||||
c := newTestClient()
|
c := newTestClient()
|
||||||
|
|
||||||
var repoName = "Reviews"
|
repoName := "Reviews"
|
||||||
repo, pull, submitter, reviewer, success := preparePullReviewTest(t, c, repoName)
|
repo, pull, submitter, reviewer, success := preparePullReviewTest(t, c, repoName)
|
||||||
if !success {
|
if !success {
|
||||||
return
|
return
|
||||||
|
@ -49,11 +49,12 @@ func TestPullReview(t *testing.T) {
|
||||||
r3, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
r3, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
||||||
State: ReviewStateApproved,
|
State: ReviewStateApproved,
|
||||||
Body: "lgtm",
|
Body: "lgtm",
|
||||||
Comments: []CreatePullReviewComment{{
|
Comments: []CreatePullReviewComment{
|
||||||
Path: "WOW-file",
|
{
|
||||||
Body: "no better name - really?",
|
Path: "WOW-file",
|
||||||
NewLineNum: 1,
|
Body: "no better name - really?",
|
||||||
},
|
NewLineNum: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -87,22 +88,24 @@ func TestPullReview(t *testing.T) {
|
||||||
c.SetSudo("")
|
c.SetSudo("")
|
||||||
r4, resp, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
r4, resp, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
||||||
Body: "...",
|
Body: "...",
|
||||||
Comments: []CreatePullReviewComment{{
|
Comments: []CreatePullReviewComment{
|
||||||
Path: "WOW-file",
|
{
|
||||||
Body: "its ok",
|
Path: "WOW-file",
|
||||||
NewLineNum: 1,
|
Body: "its ok",
|
||||||
},
|
NewLineNum: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, resp)
|
assert.NotNil(t, resp)
|
||||||
r5, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
r5, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
||||||
Body: "...",
|
Body: "...",
|
||||||
Comments: []CreatePullReviewComment{{
|
Comments: []CreatePullReviewComment{
|
||||||
Path: "WOW-file",
|
{
|
||||||
Body: "hehe and here it is",
|
Path: "WOW-file",
|
||||||
NewLineNum: 3,
|
Body: "hehe and here it is",
|
||||||
},
|
NewLineNum: 3,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -200,7 +203,7 @@ func preparePullReviewTest(t *testing.T, c *Client, repoName string) (*Repositor
|
||||||
Content: "QSBuZXcgRmlsZQoKYW5kIHNvbWUgbGluZXMK",
|
Content: "QSBuZXcgRmlsZQoKYW5kIHNvbWUgbGluZXMK",
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "creat a new file",
|
Message: "creat a new file",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
NewBranchName: "new_file",
|
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{
|
pull, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
|
||||||
Base: "master",
|
Base: "main",
|
||||||
Head: "new_file",
|
Head: "new_file",
|
||||||
Title: "Creat a NewFile",
|
Title: "Creat a NewFile",
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,8 +17,8 @@ func TestPull(t *testing.T) {
|
||||||
user, _, err := c.GetMyUserInfo()
|
user, _, err := c.GetMyUserInfo()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var repoName = "repo_pull_test"
|
repoName := "repo_pull_test"
|
||||||
var forkOrg = "ForkOrg"
|
forkOrg := "ForkOrg"
|
||||||
if !preparePullTest(t, c, repoName, forkOrg) {
|
if !preparePullTest(t, c, repoName, forkOrg) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func TestPull(t *testing.T) {
|
||||||
assert.Len(t, pulls, 0)
|
assert.Len(t, pulls, 0)
|
||||||
|
|
||||||
pullUpdateFile, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
|
pullUpdateFile, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
|
||||||
Base: "master",
|
Base: "main",
|
||||||
Head: forkOrg + ":overwrite_licence",
|
Head: forkOrg + ":overwrite_licence",
|
||||||
Title: "overwrite a file",
|
Title: "overwrite a file",
|
||||||
})
|
})
|
||||||
|
@ -37,7 +37,7 @@ func TestPull(t *testing.T) {
|
||||||
assert.NotNil(t, pullUpdateFile)
|
assert.NotNil(t, pullUpdateFile)
|
||||||
|
|
||||||
pullNewFile, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
|
pullNewFile, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
|
||||||
Base: "master",
|
Base: "main",
|
||||||
Head: forkOrg + ":new_file",
|
Head: forkOrg + ":new_file",
|
||||||
Title: "create a file",
|
Title: "create a file",
|
||||||
})
|
})
|
||||||
|
@ -45,7 +45,7 @@ func TestPull(t *testing.T) {
|
||||||
assert.NotNil(t, pullNewFile)
|
assert.NotNil(t, pullNewFile)
|
||||||
|
|
||||||
pullConflict, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
|
pullConflict, _, err := c.CreatePullRequest(c.username, repoName, CreatePullRequestOption{
|
||||||
Base: "master",
|
Base: "main",
|
||||||
Head: forkOrg + ":will_conflict",
|
Head: forkOrg + ":will_conflict",
|
||||||
Title: "this pull will conflict",
|
Title: "this pull will conflict",
|
||||||
})
|
})
|
||||||
|
@ -97,8 +97,8 @@ func TestPull(t *testing.T) {
|
||||||
// test conflict pull
|
// test conflict pull
|
||||||
pr, _, err = c.GetPullRequest(user.UserName, repoName, pullConflict.Index)
|
pr, _, err = c.GetPullRequest(user.UserName, repoName, pullConflict.Index)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.False(t, pullConflict.HasMerged)
|
assert.False(t, pr.HasMerged)
|
||||||
assert.False(t, pullConflict.Mergeable)
|
assert.False(t, pr.Mergeable)
|
||||||
merged, _, err = c.MergePullRequest(user.UserName, repoName, pullConflict.Index, MergePullRequestOption{
|
merged, _, err = c.MergePullRequest(user.UserName, repoName, pullConflict.Index, MergePullRequestOption{
|
||||||
Style: MergeStyleMerge,
|
Style: MergeStyleMerge,
|
||||||
Title: "pullConflict",
|
Title: "pullConflict",
|
||||||
|
@ -145,18 +145,18 @@ func preparePullTest(t *testing.T, c *Client, repoName, forkOrg string) bool {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, forkRepo)
|
assert.NotNil(t, forkRepo)
|
||||||
|
|
||||||
masterLicence, _, err := c.GetContents(forkRepo.Owner.UserName, forkRepo.Name, "master", "LICENSE")
|
mainLicense, _, err := c.GetContents(forkRepo.Owner.UserName, forkRepo.Name, "main", "LICENSE")
|
||||||
if !assert.NoError(t, err) || !assert.NotNil(t, masterLicence) {
|
if !assert.NoError(t, err) || !assert.NotNil(t, mainLicense) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedFile, _, err := c.UpdateFile(forkRepo.Owner.UserName, forkRepo.Name, "LICENSE", UpdateFileOptions{
|
updatedFile, _, err := c.UpdateFile(forkRepo.Owner.UserName, forkRepo.Name, "LICENSE", UpdateFileOptions{
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "Overwrite",
|
Message: "Overwrite",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
NewBranchName: "overwrite_licence",
|
NewBranchName: "overwrite_licence",
|
||||||
},
|
},
|
||||||
SHA: masterLicence.SHA,
|
SHA: mainLicense.SHA,
|
||||||
Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=",
|
Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=",
|
||||||
})
|
})
|
||||||
if !assert.NoError(t, err) || !assert.NotNil(t, updatedFile) {
|
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=",
|
Content: "QSBuZXcgRmlsZQo=",
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "creat a new file",
|
Message: "creat a new file",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
NewBranchName: "new_file",
|
NewBranchName: "new_file",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -179,7 +179,7 @@ func preparePullTest(t *testing.T, c *Client, repoName, forkOrg string) bool {
|
||||||
Content: "U3RhcnQgQ29uZmxpY3QK",
|
Content: "U3RhcnQgQ29uZmxpY3QK",
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "Start Conflict",
|
Message: "Start Conflict",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if !assert.NoError(t, err) || !assert.NotNil(t, conflictFile1) {
|
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",
|
Content: "V2lsbEhhdmUgQ29uZmxpY3QK",
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "creat a new file witch will conflict",
|
Message: "creat a new file witch will conflict",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
NewBranchName: "will_conflict",
|
NewBranchName: "will_conflict",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestRelease(t *testing.T) {
|
||||||
// CreateRelease
|
// CreateRelease
|
||||||
r, _, err := c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
r, _, err := c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
||||||
TagName: "awesome",
|
TagName: "awesome",
|
||||||
Target: "master",
|
Target: "main",
|
||||||
Title: "Release 1",
|
Title: "Release 1",
|
||||||
Note: "yes it's awesome",
|
Note: "yes it's awesome",
|
||||||
IsDraft: true,
|
IsDraft: true,
|
||||||
|
@ -38,7 +38,7 @@ func TestRelease(t *testing.T) {
|
||||||
assert.EqualValues(t, true, r.IsDraft)
|
assert.EqualValues(t, true, r.IsDraft)
|
||||||
assert.EqualValues(t, "Release 1", r.Title)
|
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, 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, "yes it's awesome", r.Note)
|
||||||
assert.EqualValues(t, c.username, r.Publisher.UserName)
|
assert.EqualValues(t, c.username, r.Publisher.UserName)
|
||||||
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
||||||
|
@ -85,7 +85,7 @@ func TestRelease(t *testing.T) {
|
||||||
// CreateRelease
|
// CreateRelease
|
||||||
_, _, err = c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
_, _, err = c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
||||||
TagName: "aNewReleaseTag",
|
TagName: "aNewReleaseTag",
|
||||||
Target: "master",
|
Target: "main",
|
||||||
Title: "Title of aNewReleaseTag",
|
Title: "Title of aNewReleaseTag",
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func TestRepoBranches(t *testing.T) {
|
func TestRepoBranches(t *testing.T) {
|
||||||
log.Println("== TestRepoBranches ==")
|
log.Println("== TestRepoBranches ==")
|
||||||
c := newTestClient()
|
c := newTestClient()
|
||||||
var repoName = "branches"
|
repoName := "branches"
|
||||||
|
|
||||||
repo := prepareBranchTest(t, c, repoName)
|
repo := prepareBranchTest(t, c, repoName)
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
|
@ -25,7 +25,7 @@ func TestRepoBranches(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, bl, 3)
|
assert.Len(t, bl, 3)
|
||||||
assert.EqualValues(t, "feature", bl[0].Name)
|
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)
|
assert.EqualValues(t, "update", bl[2].Name)
|
||||||
|
|
||||||
b, _, err := c.GetRepoBranch(repo.Owner.UserName, repo.Name, "update")
|
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.ID, b.Commit.ID)
|
||||||
assert.EqualValues(t, bl[2].Commit.Added, b.Commit.Added)
|
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.NoError(t, err)
|
||||||
assert.False(t, s)
|
assert.False(t, s)
|
||||||
s, _, err = c.DeleteRepoBranch(repo.Owner.UserName, repo.Name, "feature")
|
s, _, err = c.DeleteRepoBranch(repo.Owner.UserName, repo.Name, "feature")
|
||||||
|
@ -59,7 +59,7 @@ func TestRepoBranches(t *testing.T) {
|
||||||
func TestRepoBranchProtection(t *testing.T) {
|
func TestRepoBranchProtection(t *testing.T) {
|
||||||
log.Println("== TestRepoBranchProtection ==")
|
log.Println("== TestRepoBranchProtection ==")
|
||||||
c := newTestClient()
|
c := newTestClient()
|
||||||
var repoName = "BranchProtection"
|
repoName := "BranchProtection"
|
||||||
|
|
||||||
repo := prepareBranchTest(t, c, repoName)
|
repo := prepareBranchTest(t, c, repoName)
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
|
@ -74,7 +74,7 @@ func TestRepoBranchProtection(t *testing.T) {
|
||||||
|
|
||||||
// CreateBranchProtection
|
// CreateBranchProtection
|
||||||
bp, _, err := c.CreateBranchProtection(repo.Owner.UserName, repo.Name, CreateBranchProtectionOption{
|
bp, _, err := c.CreateBranchProtection(repo.Owner.UserName, repo.Name, CreateBranchProtectionOption{
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
EnablePush: true,
|
EnablePush: true,
|
||||||
EnablePushWhitelist: true,
|
EnablePushWhitelist: true,
|
||||||
PushWhitelistUsernames: []string{"test01"},
|
PushWhitelistUsernames: []string{"test01"},
|
||||||
|
@ -83,7 +83,7 @@ func TestRepoBranchProtection(t *testing.T) {
|
||||||
BlockOnOutdatedBranch: true,
|
BlockOnOutdatedBranch: true,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
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, false, bp.EnableStatusCheck)
|
||||||
assert.EqualValues(t, true, bp.EnablePush)
|
assert.EqualValues(t, true, bp.EnablePush)
|
||||||
assert.EqualValues(t, true, bp.EnablePushWhitelist)
|
assert.EqualValues(t, true, bp.EnablePushWhitelist)
|
||||||
|
@ -136,18 +136,18 @@ func prepareBranchTest(t *testing.T, c *Client, repoName string) *Repository {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
masterLicence, _, err := c.GetContents(origRepo.Owner.UserName, origRepo.Name, "master", "README.md")
|
mainLicense, _, err := c.GetContents(origRepo.Owner.UserName, origRepo.Name, "main", "README.md")
|
||||||
if !assert.NoError(t, err) || !assert.NotNil(t, masterLicence) {
|
if !assert.NoError(t, err) || !assert.NotNil(t, mainLicense) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedFile, _, err := c.UpdateFile(origRepo.Owner.UserName, origRepo.Name, "README.md", UpdateFileOptions{
|
updatedFile, _, err := c.UpdateFile(origRepo.Owner.UserName, origRepo.Name, "README.md", UpdateFileOptions{
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "update it",
|
Message: "update it",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
NewBranchName: "update",
|
NewBranchName: "update",
|
||||||
},
|
},
|
||||||
SHA: masterLicence.SHA,
|
SHA: mainLicense.SHA,
|
||||||
Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=",
|
Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=",
|
||||||
})
|
})
|
||||||
if !assert.NoError(t, err) || !assert.NotNil(t, updatedFile) {
|
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=",
|
Content: "QSBuZXcgRmlsZQo=",
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "creat a new file",
|
Message: "creat a new file",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
NewBranchName: "feature",
|
NewBranchName: "feature",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, repo)
|
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.NoError(t, err)
|
||||||
assert.EqualValues(t, "IyBDaGFuZ2VGaWxlcwoKQSB0ZXN0IFJlcG86IENoYW5nZUZpbGVz", base64.StdEncoding.EncodeToString(raw))
|
assert.EqualValues(t, "IyBDaGFuZ2VGaWxlcwoKQSB0ZXN0IFJlcG86IENoYW5nZUZpbGVz", base64.StdEncoding.EncodeToString(raw))
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
|
||||||
Content: "ZmlsZUEK",
|
Content: "ZmlsZUEK",
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
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))
|
assert.EqualValues(t, "ZmlsZUEK", base64.StdEncoding.EncodeToString(raw))
|
||||||
|
|
||||||
updatedFile, _, err := c.UpdateFile(repo.Owner.UserName, repo.Name, testFileName, UpdateFileOptions{
|
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.NoError(t, err)
|
||||||
assert.NotNil(t, updatedFile)
|
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.NoError(t, err)
|
||||||
assert.EqualValues(t, updatedFile.Content.SHA, file.SHA)
|
assert.EqualValues(t, updatedFile.Content.SHA, file.SHA)
|
||||||
assert.EqualValues(t, &updatedFile.Content.Content, &file.Content)
|
assert.EqualValues(t, &updatedFile.Content.Content, &file.Content)
|
||||||
|
@ -58,7 +58,7 @@ func TestFileCreateUpdateGet(t *testing.T) {
|
||||||
SHA: updatedFile.Content.SHA,
|
SHA: updatedFile.Content.SHA,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
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.Error(t, err)
|
||||||
assert.EqualValues(t, 404, resp.StatusCode)
|
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{
|
updatedFile, _, err = c.UpdateFile(repo.Owner.UserName, repo.Name, "LICENSE", UpdateFileOptions{
|
||||||
FileOptions: FileOptions{
|
FileOptions: FileOptions{
|
||||||
Message: "Overwrite",
|
Message: "Overwrite",
|
||||||
BranchName: "master",
|
BranchName: "main",
|
||||||
NewBranchName: "overwrite-a+/&licence",
|
NewBranchName: "overwrite-a+/&licence",
|
||||||
},
|
},
|
||||||
SHA: licence.SHA,
|
SHA: licence.SHA,
|
||||||
|
|
|
@ -23,12 +23,12 @@ func TestTags(t *testing.T) {
|
||||||
cTag, resp, err := c.CreateTag(repo.Owner.UserName, repo.Name, CreateTagOption{
|
cTag, resp, err := c.CreateTag(repo.Owner.UserName, repo.Name, CreateTagOption{
|
||||||
TagName: "tag1",
|
TagName: "tag1",
|
||||||
Message: cTagMSG,
|
Message: cTagMSG,
|
||||||
Target: "master",
|
Target: "main",
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 201, resp.StatusCode)
|
assert.EqualValues(t, 201, resp.StatusCode)
|
||||||
assert.EqualValues(t, cTagMSG, cTag.Message)
|
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{})
|
tags, _, err := c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -44,9 +44,8 @@ func TestTags(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, cTag.Name, aTag.Tag)
|
assert.EqualValues(t, cTag.Name, aTag.Tag)
|
||||||
assert.EqualValues(t, cTag.ID, aTag.SHA)
|
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, cTag.Message+"\n", aTag.Message)
|
||||||
assert.EqualValues(t, false, aTag.Verification.Verified)
|
|
||||||
assert.EqualValues(t, "commit", aTag.Object.Type)
|
assert.EqualValues(t, "commit", aTag.Object.Type)
|
||||||
|
|
||||||
// DeleteReleaseTag
|
// DeleteReleaseTag
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestCreateRepo(t *testing.T) {
|
||||||
user, _, err := c.GetMyUserInfo()
|
user, _, err := c.GetMyUserInfo()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var repoName = "test1"
|
repoName := "test1"
|
||||||
_, _, err = c.GetRepo(user.UserName, repoName)
|
_, _, err = c.GetRepo(user.UserName, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
repo, _, err := c.CreateRepo(CreateRepoOption{
|
repo, _, err := c.CreateRepo(CreateRepoOption{
|
||||||
|
@ -138,7 +138,7 @@ func TestGetArchive(t *testing.T) {
|
||||||
c := newTestClient()
|
c := newTestClient()
|
||||||
repo, _ := createTestRepo(t, "ToDownload", c)
|
repo, _ := createTestRepo(t, "ToDownload", c)
|
||||||
time.Sleep(time.Second / 2)
|
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.NoError(t, err)
|
||||||
assert.True(t, len(archive) > 1500 && len(archive) < 1700)
|
assert.True(t, len(archive) > 1500 && len(archive) < 1700)
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func TestGetArchiveReader(t *testing.T) {
|
||||||
c := newTestClient()
|
c := newTestClient()
|
||||||
repo, _ := createTestRepo(t, "ToDownload", c)
|
repo, _ := createTestRepo(t, "ToDownload", c)
|
||||||
time.Sleep(time.Second / 2)
|
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)
|
assert.NoError(t, err)
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
|
@ -177,11 +177,15 @@ func TestGetRepoByID(t *testing.T) {
|
||||||
func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) {
|
func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) {
|
||||||
user, _, uErr := c.GetMyUserInfo()
|
user, _, uErr := c.GetMyUserInfo()
|
||||||
assert.NoError(t, uErr)
|
assert.NoError(t, uErr)
|
||||||
_, _, err := c.GetRepo(user.UserName, name)
|
repo, _, err := c.GetRepo(user.UserName, name)
|
||||||
if err == nil {
|
// 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)
|
_, _ = c.DeleteRepo(user.UserName, name)
|
||||||
}
|
}
|
||||||
repo, _, err := c.CreateRepo(CreateRepoOption{
|
|
||||||
|
repo, _, err = c.CreateRepo(CreateRepoOption{
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: "A test Repo: " + name,
|
Description: "A test Repo: " + name,
|
||||||
AutoInit: true,
|
AutoInit: true,
|
||||||
|
|
|
@ -20,20 +20,21 @@ func TestRepoTransfer(t *testing.T) {
|
||||||
repo, err := createTestRepo(t, "ToMove", c)
|
repo, err := createTestRepo(t, "ToMove", c)
|
||||||
assert.NoError(t, err)
|
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.NoError(t, err) // admin transfer repository will execute immediately but not set as pendding.
|
||||||
assert.NotNil(t, newRepo)
|
assert.NotNil(t, newRepo)
|
||||||
assert.EqualValues(t, "ToMove", newRepo.Name)
|
assert.EqualValues(t, "ToMove", newRepo.Name)
|
||||||
|
|
||||||
repo, err = createTestRepo(t, "ToMove", c)
|
repo, err = createTestRepo(t, "ToMove", c)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, _, err = c.TransferRepo(repo.Owner.UserName, repo.Name, TransferRepoOption{NewOwner: org.UserName})
|
_, resp, err := c.TransferRepo(c.username, repo.Name, TransferRepoOption{NewOwner: org.UserName})
|
||||||
assert.Error(t, err, err.Error()) // org.UserName/repo.Name has exist
|
assert.EqualValues(t, 422, resp.StatusCode)
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
_, err = c.DeleteRepo(repo.Owner.UserName, repo.Name)
|
_, err = c.DeleteRepo(repo.Owner.UserName, repo.Name)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = c.DeleteRepo(newRepo.Owner.UserName, newRepo.Name)
|
_, err = c.DeleteRepo(newRepo.Owner.UserName, newRepo.Name)
|
||||||
assert.Error(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = c.DeleteOrg(org.UserName)
|
_, err = c.DeleteOrg(org.UserName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue