mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-24 08:02:18 +02:00
Use Goblin Assert as intended (#501)
this allow for better debugging if an error occur
This commit is contained in:
parent
58838f225c
commit
aca5fddcf3
@ -27,13 +27,13 @@ func TestMatrix(t *testing.T) {
|
||||
|
||||
g.It("Should return empty array if no matrix", func() {
|
||||
axis, err := ParseString("")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(axis) == 0).IsTrue()
|
||||
})
|
||||
|
||||
g.It("Should return included axis", func() {
|
||||
axis, err := ParseString(fakeMatrixInclude)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(axis)).Equal(2)
|
||||
g.Assert(axis[0]["go_version"]).Equal("1.5")
|
||||
g.Assert(axis[1]["go_version"]).Equal("1.6")
|
||||
|
@ -47,7 +47,7 @@ func TestBoolTrue(t *testing.T) {
|
||||
in := []byte("abc") // string value should fail parse
|
||||
out := BoolTrue{}
|
||||
err := yaml.Unmarshal(in, &out)
|
||||
g.Assert(err != nil).IsTrue("expects error")
|
||||
g.Assert(err).IsNotNil("expects error")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -51,13 +51,13 @@ func TestSecret(t *testing.T) {
|
||||
secret := Secret{}
|
||||
secret.Value = "secretvalue"
|
||||
err := secret.Validate()
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
g.It("when no value", func() {
|
||||
secret := Secret{}
|
||||
secret.Name = "secretname"
|
||||
err := secret.Validate()
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -64,13 +64,13 @@ func Test_bitbucket(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "", nil)
|
||||
_, err := c.Login(ctx, w, r)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(w.Code).Equal(http.StatusSeeOther)
|
||||
})
|
||||
g.It("Should return authenticated user", func() {
|
||||
r, _ := http.NewRequest("GET", "?code=code", nil)
|
||||
u, err := c.Login(ctx, nil, r)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(u.Login).Equal(fakeUser.Login)
|
||||
g.Assert(u.Token).Equal("2YotnFZFEjr1zCsicMWpAA")
|
||||
g.Assert(u.Secret).Equal("tGzv3JOkF0XG5Qx2TlKWIA")
|
||||
@ -79,48 +79,48 @@ func Test_bitbucket(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "?code=code_bad_request", nil)
|
||||
_, err := c.Login(ctx, w, r)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
g.It("Should handle failure to resolve user", func() {
|
||||
r, _ := http.NewRequest("GET", "?code=code_user_not_found", nil)
|
||||
_, err := c.Login(ctx, nil, r)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
g.It("Should handle authentication errors", func() {
|
||||
r, _ := http.NewRequest("GET", "?error=invalid_scope", nil)
|
||||
_, err := c.Login(ctx, nil, r)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Given an access token", func() {
|
||||
g.It("Should return the authenticated user", func() {
|
||||
login, err := c.Auth(ctx, fakeUser.Token, fakeUser.Secret)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(login).Equal(fakeUser.Login)
|
||||
})
|
||||
g.It("Should handle a failure to resolve user", func() {
|
||||
_, err := c.Auth(ctx, fakeUserNotFound.Token, fakeUserNotFound.Secret)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Given a refresh token", func() {
|
||||
g.It("Should return a refresh access token", func() {
|
||||
ok, err := c.Refresh(ctx, fakeUserRefresh)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(ok).IsTrue()
|
||||
g.Assert(fakeUserRefresh.Token).Equal("2YotnFZFEjr1zCsicMWpAA")
|
||||
g.Assert(fakeUserRefresh.Secret).Equal("tGzv3JOkF0XG5Qx2TlKWIA")
|
||||
})
|
||||
g.It("Should handle an empty access token", func() {
|
||||
ok, err := c.Refresh(ctx, fakeUserRefreshEmpty)
|
||||
g.Assert(err == nil).IsFalse()
|
||||
g.Assert(err).IsNotNil()
|
||||
g.Assert(ok).IsFalse()
|
||||
})
|
||||
g.It("Should handle a failure to refresh", func() {
|
||||
ok, err := c.Refresh(ctx, fakeUserRefreshFail)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
g.Assert(ok).IsFalse()
|
||||
})
|
||||
})
|
||||
@ -128,37 +128,37 @@ func Test_bitbucket(t *testing.T) {
|
||||
g.Describe("When requesting a repository", func() {
|
||||
g.It("Should return the details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
||||
})
|
||||
g.It("Should handle not found errors", func() {
|
||||
_, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When requesting repository permissions", func() {
|
||||
g.It("Should handle not found errors", func() {
|
||||
_, err := c.Perm(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
g.It("Should authorize read access", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, fakeRepoReadOnly.Owner, fakeRepoReadOnly.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
g.Assert(perm.Push).IsFalse()
|
||||
g.Assert(perm.Admin).IsFalse()
|
||||
})
|
||||
g.It("Should authorize write access", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, fakeRepoWriteOnly.Owner, fakeRepoWriteOnly.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Admin).IsFalse()
|
||||
})
|
||||
g.It("Should authorize admin access", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, fakeRepoAdmin.Owner, fakeRepoAdmin.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Admin).IsTrue()
|
||||
@ -168,67 +168,67 @@ func Test_bitbucket(t *testing.T) {
|
||||
g.Describe("When requesting user repositories", func() {
|
||||
g.It("Should return the details", func() {
|
||||
repos, err := c.Repos(ctx, fakeUser)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repos[0].FullName).Equal(fakeRepo.FullName)
|
||||
})
|
||||
g.It("Should handle organization not found errors", func() {
|
||||
_, err := c.Repos(ctx, fakeUserNoTeams)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
g.It("Should handle not found errors", func() {
|
||||
_, err := c.Repos(ctx, fakeUserNoRepos)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When requesting user teams", func() {
|
||||
g.It("Should return the details", func() {
|
||||
teams, err := c.Teams(ctx, fakeUser)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(teams[0].Login).Equal("superfriends")
|
||||
g.Assert(teams[0].Avatar).Equal("http://i.imgur.com/ZygP55A.jpg")
|
||||
})
|
||||
g.It("Should handle not found error", func() {
|
||||
_, err := c.Teams(ctx, fakeUserNoTeams)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When downloading a file", func() {
|
||||
g.It("Should return the bytes", func() {
|
||||
raw, err := c.File(ctx, fakeUser, fakeRepo, fakeBuild, "file")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(raw) != 0).IsTrue()
|
||||
})
|
||||
g.It("Should handle not found error", func() {
|
||||
_, err := c.File(ctx, fakeUser, fakeRepo, fakeBuild, "file_not_found")
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When activating a repository", func() {
|
||||
g.It("Should error when malformed hook", func() {
|
||||
err := c.Activate(ctx, fakeUser, fakeRepo, "%gh&%ij")
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
g.It("Should create the hook", func() {
|
||||
err := c.Activate(ctx, fakeUser, fakeRepo, "http://127.0.0.1")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When deactivating a repository", func() {
|
||||
g.It("Should error when listing hooks fails", func() {
|
||||
err := c.Deactivate(ctx, fakeUser, fakeRepoNoHooks, "http://127.0.0.1")
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
g.It("Should successfully remove hooks", func() {
|
||||
err := c.Deactivate(ctx, fakeUser, fakeRepo, "http://127.0.0.1")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
g.It("Should successfully deactivate when hook already removed", func() {
|
||||
err := c.Deactivate(ctx, fakeUser, fakeRepoEmptyHook, "http://127.0.0.1")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
})
|
||||
|
||||
@ -245,18 +245,18 @@ func Test_bitbucket(t *testing.T) {
|
||||
{Url: "http://localhost/hook"},
|
||||
}
|
||||
hook := matchingHooks(hooks, "http://127.0.0.1/")
|
||||
g.Assert(hook == nil).IsTrue()
|
||||
g.Assert(hook).IsNil()
|
||||
})
|
||||
g.It("Should handle malformed hook urls", func() {
|
||||
var hooks []*internal.Hook
|
||||
hook := matchingHooks(hooks, "%gh&%ij")
|
||||
g.Assert(hook == nil).IsTrue()
|
||||
g.Assert(hook).IsNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.It("Should update the status", func() {
|
||||
err := c.Status(ctx, fakeUser, fakeRepo, fakeBuild, "http://127.0.0.1", nil)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.It("Should parse the hook", func() {
|
||||
@ -266,7 +266,7 @@ func Test_bitbucket(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
|
||||
r, _, err := c.Hook(req)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r.FullName).Equal("user_name/repo_name")
|
||||
})
|
||||
|
||||
|
@ -36,9 +36,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, "issue:created")
|
||||
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.Describe("Given a pull request hook payload", func() {
|
||||
@ -50,7 +50,7 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPullCreated)
|
||||
|
||||
_, _, err := parseHook(req)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
|
||||
g.It("Should return nil if not open", func() {
|
||||
@ -60,9 +60,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPullCreated)
|
||||
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.It("Should return pull request details", func() {
|
||||
@ -72,7 +72,7 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPullCreated)
|
||||
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r.FullName).Equal("user_name/repo_name")
|
||||
g.Assert(b.Commit).Equal("ce5965ddd289")
|
||||
})
|
||||
@ -87,7 +87,7 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
|
||||
_, _, err := parseHook(req)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
|
||||
g.It("Should return nil if missing commit sha", func() {
|
||||
@ -97,9 +97,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.It("Should return push details", func() {
|
||||
@ -109,7 +109,7 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r.FullName).Equal("user_name/repo_name")
|
||||
g.Assert(b.Commit).Equal("709d658dc5b6d6afcd46049c2f332ee3f515a67d")
|
||||
})
|
||||
|
@ -70,13 +70,13 @@ func Test_coding(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "", nil)
|
||||
_, err := c.Login(ctx, w, r)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(w.Code).Equal(http.StatusSeeOther)
|
||||
})
|
||||
g.It("Should return authenticated user", func() {
|
||||
r, _ := http.NewRequest("GET", "?code=code", nil)
|
||||
u, err := c.Login(ctx, nil, r)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(u.Login).Equal(fakeUser.Login)
|
||||
g.Assert(u.Token).Equal(fakeUser.Token)
|
||||
g.Assert(u.Secret).Equal(fakeUser.Secret)
|
||||
@ -86,19 +86,19 @@ func Test_coding(t *testing.T) {
|
||||
g.Describe("Given an access token", func() {
|
||||
g.It("Should return the anthenticated user", func() {
|
||||
login, err := c.Auth(ctx, fakeUser.Token, fakeUser.Secret)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(login).Equal(fakeUser.Login)
|
||||
})
|
||||
g.It("Should handle a failure to resolve user", func() {
|
||||
_, err := c.Auth(ctx, fakeUserNotFound.Token, fakeUserNotFound.Secret)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Given a refresh token", func() {
|
||||
g.It("Should return a refresh access token", func() {
|
||||
ok, err := c.Refresh(ctx, fakeUserRefresh)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(ok).IsTrue()
|
||||
g.Assert(fakeUserRefresh.Token).Equal("VDZupx0usVRV4oOd1FCu4xUxgk8SY0TK")
|
||||
g.Assert(fakeUserRefresh.Secret).Equal("BenBQq7TWZ7Cp0aUM47nQjTz2QHNmTWcPctB609n")
|
||||
@ -112,7 +112,7 @@ func Test_coding(t *testing.T) {
|
||||
g.Describe("When requesting a repository", func() {
|
||||
g.It("Should return the details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
||||
g.Assert(repo.Avatar).Equal(s.URL + fakeRepo.Avatar)
|
||||
g.Assert(repo.Link).Equal(s.URL + fakeRepo.Link)
|
||||
@ -123,49 +123,49 @@ func Test_coding(t *testing.T) {
|
||||
})
|
||||
g.It("Should handle not found errors", func() {
|
||||
_, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When requesting repository permissions", func() {
|
||||
g.It("Should authorize admin access for project owner", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, "demo1", "perm_owner")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Admin).IsTrue()
|
||||
})
|
||||
g.It("Should authorize admin access for project admin", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, "demo1", "perm_admin")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Admin).IsTrue()
|
||||
})
|
||||
g.It("Should authorize read access for project member", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, "demo1", "perm_member")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Admin).IsFalse()
|
||||
})
|
||||
g.It("Should authorize no access for project guest", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, "demo1", "perm_guest")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Pull).IsFalse()
|
||||
g.Assert(perm.Push).IsFalse()
|
||||
g.Assert(perm.Admin).IsFalse()
|
||||
})
|
||||
g.It("Should handle not found errors", func() {
|
||||
_, err := c.Perm(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When downloading a file", func() {
|
||||
g.It("Should return file for specified build", func() {
|
||||
data, err := c.File(ctx, fakeUser, fakeRepo, fakeBuild, ".woodpecker.yml")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(string(data)).Equal("pipeline:\n test:\n image: golang:1.6\n commands:\n - go test\n")
|
||||
})
|
||||
})
|
||||
@ -178,7 +178,7 @@ func Test_coding(t *testing.T) {
|
||||
Password: "password",
|
||||
})
|
||||
netrc, err := remote.Netrc(fakeUser, nil)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(netrc.Login).Equal("someuser")
|
||||
g.Assert(netrc.Password).Equal("password")
|
||||
g.Assert(netrc.Machine).Equal("git.coding.net")
|
||||
@ -188,7 +188,7 @@ func Test_coding(t *testing.T) {
|
||||
Machine: "git.coding.net",
|
||||
})
|
||||
netrc, err := remote.Netrc(fakeUser, nil)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(netrc.Login).Equal(fakeUser.Token)
|
||||
g.Assert(netrc.Password).Equal("x-oauth-basic")
|
||||
g.Assert(netrc.Machine).Equal("git.coding.net")
|
||||
@ -198,22 +198,22 @@ func Test_coding(t *testing.T) {
|
||||
g.Describe("When activating a repository", func() {
|
||||
g.It("Should create the hook", func() {
|
||||
err := c.Activate(ctx, fakeUser, fakeRepo, "http://127.0.0.1")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
g.It("Should update the hook when exists", func() {
|
||||
err := c.Activate(ctx, fakeUser, fakeRepo, "http://127.0.0.2")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When deactivating a repository", func() {
|
||||
g.It("Should successfully remove hook", func() {
|
||||
err := c.Deactivate(ctx, fakeUser, fakeRepo, "http://127.0.0.3")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
g.It("Should successfully deactivate when hook already removed", func() {
|
||||
err := c.Deactivate(ctx, fakeUser, fakeRepo, "http://127.0.0.4")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
})
|
||||
|
||||
@ -225,7 +225,7 @@ func Test_coding(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
|
||||
r, _, err := c.Hook(req)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r.FullName).Equal("demo1/test1")
|
||||
})
|
||||
})
|
||||
|
@ -63,7 +63,7 @@ func Test_hook(t *testing.T) {
|
||||
}
|
||||
|
||||
actualRepo, actualBuild, err := parseHook(r)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(actualRepo).Equal(repo)
|
||||
g.Assert(actualBuild).Equal(build)
|
||||
})
|
||||
@ -102,7 +102,7 @@ func Test_hook(t *testing.T) {
|
||||
Kind: model.RepoGit,
|
||||
}
|
||||
actual, err := convertRepository(repository)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(actual).Equal(repo)
|
||||
})
|
||||
|
||||
@ -130,16 +130,16 @@ func Test_hook(t *testing.T) {
|
||||
}
|
||||
|
||||
actualRepo, actualBuild, err := parsePushHook([]byte(fixtures.PushHook))
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(actualRepo).Equal(repo)
|
||||
g.Assert(actualBuild).Equal(build)
|
||||
})
|
||||
|
||||
g.It("Should parse delete branch push hook", func() {
|
||||
actualRepo, actualBuild, err := parsePushHook([]byte(fixtures.DeleteBranchPushHook))
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(actualRepo == nil).IsTrue()
|
||||
g.Assert(actualBuild == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(actualRepo).IsNil()
|
||||
g.Assert(actualBuild).IsNil()
|
||||
})
|
||||
|
||||
g.It("Should parse pull request hook", func() {
|
||||
@ -167,7 +167,7 @@ func Test_hook(t *testing.T) {
|
||||
}
|
||||
|
||||
actualRepo, actualBuild, err := parsePullRequestHook([]byte(fixtures.PullRequestHook))
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(actualRepo).Equal(repo)
|
||||
g.Assert(actualBuild).Equal(build)
|
||||
})
|
||||
@ -197,7 +197,7 @@ func Test_hook(t *testing.T) {
|
||||
}
|
||||
|
||||
actualRepo, actualBuild, err := parseMergeReuqestHook([]byte(fixtures.MergeRequestHook))
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(actualRepo).Equal(repo)
|
||||
g.Assert(actualBuild).Equal(build)
|
||||
})
|
||||
|
@ -63,7 +63,7 @@ func Test_gitea(t *testing.T) {
|
||||
})
|
||||
g.It("Should handle malformed url", func() {
|
||||
_, err := New(Opts{URL: "%gh&%ij"})
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
@ -93,7 +93,7 @@ func Test_gitea(t *testing.T) {
|
||||
g.Describe("Requesting a repository", func() {
|
||||
g.It("Should return the repository details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repo.FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||
@ -103,57 +103,57 @@ func Test_gitea(t *testing.T) {
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Requesting repository permissions", func() {
|
||||
g.It("Should return the permission details", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Admin).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Perm(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Requesting a repository list", func() {
|
||||
g.It("Should return the repository list", func() {
|
||||
repos, err := c.Repos(ctx, fakeUser)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Repos(ctx, fakeUserNoRepos)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.It("Should register repository hooks", func() {
|
||||
err := c.Activate(ctx, fakeUser, fakeRepo, "http://localhost")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.It("Should remove repository hooks", func() {
|
||||
err := c.Deactivate(ctx, fakeUser, fakeRepo, "http://localhost")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.It("Should return a repository file", func() {
|
||||
raw, err := c.File(ctx, fakeUser, fakeRepo, fakeBuild, ".woodpecker.yml")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(string(raw)).Equal("{ platform: linux/amd64 }")
|
||||
})
|
||||
|
||||
g.It("Should return nil from send build status", func() {
|
||||
err := c.Status(ctx, fakeUser, fakeRepo, fakeBuild, "http://gitea.io", nil)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.Describe("Given an authentication request", func() {
|
||||
|
@ -33,7 +33,7 @@ func Test_parse(t *testing.T) {
|
||||
g.It("Should parse push hook payload", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPush)
|
||||
hook, err := parsePush(buf)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(hook.Ref).Equal("refs/heads/master")
|
||||
g.Assert(hook.After).Equal("ef98532add3b2feb7a137426bba1248724367df5")
|
||||
g.Assert(hook.Before).Equal("4b2626259b5a97b6b4eab5e6cca66adb986b672b")
|
||||
@ -57,7 +57,7 @@ func Test_parse(t *testing.T) {
|
||||
g.It("Should parse tag hook payload", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPushTag)
|
||||
hook, err := parsePush(buf)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(hook.Ref).Equal("v1.0.0")
|
||||
g.Assert(hook.Sha).Equal("ef98532add3b2feb7a137426bba1248724367df5")
|
||||
g.Assert(hook.Repo.Name).Equal("hello-world")
|
||||
@ -73,7 +73,7 @@ func Test_parse(t *testing.T) {
|
||||
g.It("Should parse pull_request hook payload", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPullRequest)
|
||||
hook, err := parsePullRequest(buf)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(hook.Action).Equal("opened")
|
||||
g.Assert(hook.Number).Equal(int64(1))
|
||||
|
||||
|
@ -34,9 +34,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header = http.Header{}
|
||||
req.Header.Set(hookEvent, "issues")
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
g.Describe("given a push hook", func() {
|
||||
g.It("should extract repository and build details", func() {
|
||||
@ -45,9 +45,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header = http.Header{}
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r != nil).IsTrue()
|
||||
g.Assert(b != nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPush)
|
||||
g.Assert(b.ChangedFiles).Equal([]string{"CHANGELOG.md", "app/controller/application.rb"})
|
||||
})
|
||||
|
@ -68,7 +68,7 @@ func Test_github(t *testing.T) {
|
||||
})
|
||||
g.It("Should handle malformed url", func() {
|
||||
_, err := New(Opts{URL: "%gh&%ij"})
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
@ -98,7 +98,7 @@ func Test_github(t *testing.T) {
|
||||
g.Describe("Requesting a repository", func() {
|
||||
g.It("Should return the repository details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
||||
@ -108,21 +108,21 @@ func Test_github(t *testing.T) {
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Requesting repository permissions", func() {
|
||||
g.It("Should return the permission details", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Admin).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Perm(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -37,18 +37,18 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, "issues")
|
||||
|
||||
r, b, err := parseHook(req, false)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.Describe("given a push hook", func() {
|
||||
g.It("should skip when action is deleted", func() {
|
||||
raw := []byte(fixtures.HookPushDeleted)
|
||||
r, b, err := parsePushHook(raw)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
g.It("should extract repository and build details", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPush)
|
||||
@ -57,9 +57,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
|
||||
r, b, err := parseHook(req, false)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r != nil).IsTrue()
|
||||
g.Assert(b != nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPush)
|
||||
expectedFiles := []string{"CHANGELOG.md", "app/controller/application.rb"}
|
||||
g.Assert(b.ChangedFiles).Equal(expectedFiles)
|
||||
@ -70,16 +70,16 @@ func Test_parser(t *testing.T) {
|
||||
g.It("should skip when action is not open or sync", func() {
|
||||
raw := []byte(fixtures.HookPullRequestInvalidAction)
|
||||
r, b, err := parsePullHook(raw, false)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
g.It("should skip when state is not open", func() {
|
||||
raw := []byte(fixtures.HookPullRequestInvalidState)
|
||||
r, b, err := parsePullHook(raw, false)
|
||||
g.Assert(r == nil).IsTrue()
|
||||
g.Assert(b == nil).IsTrue()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
g.It("should extract repository and build details", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPullRequest)
|
||||
@ -88,9 +88,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookPull)
|
||||
|
||||
r, b, err := parseHook(req, false)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r != nil).IsTrue()
|
||||
g.Assert(b != nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPull)
|
||||
})
|
||||
})
|
||||
@ -103,9 +103,9 @@ func Test_parser(t *testing.T) {
|
||||
req.Header.Set(hookEvent, hookDeploy)
|
||||
|
||||
r, b, err := parseHook(req, false)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(r != nil).IsTrue()
|
||||
g.Assert(b != nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventDeploy)
|
||||
})
|
||||
})
|
||||
|
@ -85,7 +85,7 @@ func Test_Gitlab(t *testing.T) {
|
||||
client.HideArchives = false
|
||||
_projects, err := client.Repos(ctx, &user)
|
||||
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(_projects)).Equal(2)
|
||||
})
|
||||
})
|
||||
@ -125,7 +125,7 @@ func Test_Gitlab(t *testing.T) {
|
||||
g.It("Should return error, when repo is not exist", func() {
|
||||
_, err := client.Perm(ctx, &user, "not-existed", "not-existed")
|
||||
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
@ -139,7 +139,7 @@ func Test_Gitlab(t *testing.T) {
|
||||
g.It("Should be failed, when token not given", func() {
|
||||
err := client.Activate(ctx, &user, &repo, "http://example.com/api/hook/test/test")
|
||||
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
@ -148,7 +148,7 @@ func Test_Gitlab(t *testing.T) {
|
||||
g.It("Should be success", func() {
|
||||
err := client.Deactivate(ctx, &user, &repo, "http://example.com/api/hook/test/test?access_token=token")
|
||||
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -61,7 +61,7 @@ func Test_gogs(t *testing.T) {
|
||||
})
|
||||
g.It("Should handle malformed url", func() {
|
||||
_, err := New(Opts{URL: "%gh&%ij"})
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
@ -91,7 +91,7 @@ func Test_gogs(t *testing.T) {
|
||||
g.Describe("Requesting a repository", func() {
|
||||
g.It("Should return the repository details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repo.FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||
@ -101,52 +101,52 @@ func Test_gogs(t *testing.T) {
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Requesting repository permissions", func() {
|
||||
g.It("Should return the permission details", func() {
|
||||
perm, err := c.Perm(ctx, fakeUser, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(perm.Admin).IsTrue()
|
||||
g.Assert(perm.Push).IsTrue()
|
||||
g.Assert(perm.Pull).IsTrue()
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Perm(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("Requesting a repository list", func() {
|
||||
g.It("Should return the repository list", func() {
|
||||
repos, err := c.Repos(ctx, fakeUser)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||
})
|
||||
g.It("Should handle a not found error", func() {
|
||||
_, err := c.Repos(ctx, fakeUserNoRepos)
|
||||
g.Assert(err != nil).IsTrue()
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.It("Should register repositroy hooks", func() {
|
||||
err := c.Activate(ctx, fakeUser, fakeRepo, "http://localhost")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
})
|
||||
|
||||
g.It("Should return a repository file", func() {
|
||||
raw, err := c.File(ctx, fakeUser, fakeRepo, fakeBuild, ".woodpecker.yml")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(string(raw)).Equal("{ platform: linux/amd64 }")
|
||||
})
|
||||
|
||||
g.It("Should return a repository file from a ref", func() {
|
||||
raw, err := c.File(ctx, fakeUser, fakeRepo, fakeBuildWithRef, ".woodpecker.yml")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(string(raw)).Equal("{ platform: linux/amd64 }")
|
||||
})
|
||||
|
||||
@ -167,9 +167,9 @@ func Test_gogs(t *testing.T) {
|
||||
_, err1 := c.Auth(ctx, "octocat", "4vyW6b49Z")
|
||||
err2 := c.Status(ctx, nil, nil, nil, "", nil)
|
||||
err3 := c.Deactivate(ctx, nil, nil, "")
|
||||
g.Assert(err1 != nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNotNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func Test_parse(t *testing.T) {
|
||||
g.It("Should parse push hook payload", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPush)
|
||||
hook, err := parsePush(buf)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(hook.Ref).Equal("refs/heads/master")
|
||||
g.Assert(hook.After).Equal("ef98532add3b2feb7a137426bba1248724367df5")
|
||||
g.Assert(hook.Before).Equal("4b2626259b5a97b6b4eab5e6cca66adb986b672b")
|
||||
@ -55,7 +55,7 @@ func Test_parse(t *testing.T) {
|
||||
g.It("Should parse tag hook payload", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPushTag)
|
||||
hook, err := parsePush(buf)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(hook.Ref).Equal("v1.0.0")
|
||||
g.Assert(hook.Repo.Name).Equal("hello-world")
|
||||
g.Assert(hook.Repo.URL).Equal("http://gogs.golang.org/gordon/hello-world")
|
||||
@ -70,7 +70,7 @@ func Test_parse(t *testing.T) {
|
||||
g.It("Should parse pull_request hook payload", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPullRequest)
|
||||
hook, err := parsePullRequest(buf)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(hook.Action).Equal("opened")
|
||||
g.Assert(hook.Number).Equal(int64(1))
|
||||
|
||||
|
@ -58,13 +58,13 @@ func TestBuilds(t *testing.T) {
|
||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||
}
|
||||
err := s.CreateBuild(&build)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(build.ID != 0).IsTrue()
|
||||
g.Assert(build.Number).Equal(1)
|
||||
g.Assert(build.Commit).Equal("85f8c029b902ed9400bc600bac301a0aadb144ac")
|
||||
|
||||
count, err := s.GetBuildCount()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(count > 0).IsTrue()
|
||||
fmt.Println("GOT COUNT", count)
|
||||
})
|
||||
@ -80,8 +80,8 @@ func TestBuilds(t *testing.T) {
|
||||
build.Status = model.StatusRunning
|
||||
err1 := s.UpdateBuild(&build)
|
||||
getbuild, err2 := s.GetBuild(build.ID)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(build.ID).Equal(getbuild.ID)
|
||||
g.Assert(build.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build.Status).Equal(getbuild.Status)
|
||||
@ -95,7 +95,7 @@ func TestBuilds(t *testing.T) {
|
||||
}
|
||||
s.CreateBuild(&build, []*model.Proc{}...)
|
||||
getbuild, err := s.GetBuild(build.ID)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(build.ID).Equal(getbuild.ID)
|
||||
g.Assert(build.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build.Status).Equal(getbuild.Status)
|
||||
@ -113,9 +113,9 @@ func TestBuilds(t *testing.T) {
|
||||
err1 := s.CreateBuild(build1, []*model.Proc{}...)
|
||||
err2 := s.CreateBuild(build2, []*model.Proc{}...)
|
||||
getbuild, err3 := s.GetBuildNumber(&model.Repo{ID: 1}, build2.Number)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(build2.ID).Equal(getbuild.ID)
|
||||
g.Assert(build2.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build2.Number).Equal(getbuild.Number)
|
||||
@ -135,9 +135,9 @@ func TestBuilds(t *testing.T) {
|
||||
err1 := s.CreateBuild(build1, []*model.Proc{}...)
|
||||
err2 := s.CreateBuild(build2, []*model.Proc{}...)
|
||||
getbuild, err3 := s.GetBuildRef(&model.Repo{ID: 1}, "refs/pull/6")
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(build2.ID).Equal(getbuild.ID)
|
||||
g.Assert(build2.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build2.Number).Equal(getbuild.Number)
|
||||
@ -158,9 +158,9 @@ func TestBuilds(t *testing.T) {
|
||||
err1 := s.CreateBuild(build1, []*model.Proc{}...)
|
||||
err2 := s.CreateBuild(build2, []*model.Proc{}...)
|
||||
getbuild, err3 := s.GetBuildRef(&model.Repo{ID: 1}, "refs/pull/6")
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(build2.ID).Equal(getbuild.ID)
|
||||
g.Assert(build2.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build2.Number).Equal(getbuild.Number)
|
||||
@ -183,9 +183,9 @@ func TestBuilds(t *testing.T) {
|
||||
err1 := s.CreateBuild(build1, []*model.Proc{}...)
|
||||
err2 := s.CreateBuild(build2, []*model.Proc{}...)
|
||||
getbuild, err3 := s.GetBuildCommit(&model.Repo{ID: 1}, build2.Commit, build2.Branch)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(build2.ID).Equal(getbuild.ID)
|
||||
g.Assert(build2.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build2.Number).Equal(getbuild.Number)
|
||||
@ -211,9 +211,9 @@ func TestBuilds(t *testing.T) {
|
||||
err1 := s.CreateBuild(build1, []*model.Proc{}...)
|
||||
err2 := s.CreateBuild(build2, []*model.Proc{}...)
|
||||
getbuild, err3 := s.GetBuildLast(&model.Repo{ID: 1}, build2.Branch)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(build2.ID).Equal(getbuild.ID)
|
||||
g.Assert(build2.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build2.Number).Equal(getbuild.Number)
|
||||
@ -245,10 +245,10 @@ func TestBuilds(t *testing.T) {
|
||||
err2 := s.CreateBuild(build2, []*model.Proc{}...)
|
||||
err3 := s.CreateBuild(build3, []*model.Proc{}...)
|
||||
getbuild, err4 := s.GetBuildLastBefore(&model.Repo{ID: 1}, build3.Branch, build3.ID)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err4 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(err4).IsNil()
|
||||
g.Assert(build2.ID).Equal(getbuild.ID)
|
||||
g.Assert(build2.RepoID).Equal(getbuild.RepoID)
|
||||
g.Assert(build2.Number).Equal(getbuild.Number)
|
||||
@ -269,7 +269,7 @@ func TestBuilds(t *testing.T) {
|
||||
s.CreateBuild(build1, []*model.Proc{}...)
|
||||
s.CreateBuild(build2, []*model.Proc{}...)
|
||||
builds, err := s.GetBuildList(&model.Repo{ID: 1}, 1)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(builds)).Equal(2)
|
||||
g.Assert(builds[0].ID).Equal(build2.ID)
|
||||
g.Assert(builds[0].RepoID).Equal(build2.RepoID)
|
||||
|
@ -49,9 +49,9 @@ func TestRepos(t *testing.T) {
|
||||
err2 := s.UpdateRepo(&repo)
|
||||
getrepo, err3 := s.GetRepo(repo.ID)
|
||||
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(repo.ID).Equal(getrepo.ID)
|
||||
})
|
||||
|
||||
@ -63,7 +63,7 @@ func TestRepos(t *testing.T) {
|
||||
Name: "test",
|
||||
}
|
||||
err := s.CreateRepo(&repo)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.ID != 0).IsTrue()
|
||||
})
|
||||
|
||||
@ -76,7 +76,7 @@ func TestRepos(t *testing.T) {
|
||||
}
|
||||
s.CreateRepo(&repo)
|
||||
getrepo, err := s.GetRepo(repo.ID)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.ID).Equal(getrepo.ID)
|
||||
g.Assert(repo.UserID).Equal(getrepo.UserID)
|
||||
g.Assert(repo.Owner).Equal(getrepo.Owner)
|
||||
@ -92,7 +92,7 @@ func TestRepos(t *testing.T) {
|
||||
}
|
||||
s.CreateRepo(&repo)
|
||||
getrepo, err := s.GetRepoName(repo.FullName)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.ID).Equal(getrepo.ID)
|
||||
g.Assert(repo.UserID).Equal(getrepo.UserID)
|
||||
g.Assert(repo.Owner).Equal(getrepo.Owner)
|
||||
@ -114,8 +114,8 @@ func TestRepos(t *testing.T) {
|
||||
}
|
||||
err1 := s.CreateRepo(&repo1)
|
||||
err2 := s.CreateRepo(&repo2)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsFalse()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNotNil()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ func TestUsers(t *testing.T) {
|
||||
err1 := s.CreateUser(&user)
|
||||
err2 := s.UpdateUser(&user)
|
||||
getuser, err3 := s.GetUser(user.ID)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsTrue()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNil()
|
||||
g.Assert(user.ID).Equal(getuser.ID)
|
||||
})
|
||||
|
||||
@ -60,7 +60,7 @@ func TestUsers(t *testing.T) {
|
||||
Token: "e42080dddf012c718e476da161d21ad5",
|
||||
}
|
||||
err := s.CreateUser(&user)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(user.ID != 0).IsTrue()
|
||||
})
|
||||
|
||||
@ -76,7 +76,7 @@ func TestUsers(t *testing.T) {
|
||||
|
||||
s.CreateUser(&user)
|
||||
getuser, err := s.GetUser(user.ID)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(user.ID).Equal(getuser.ID)
|
||||
g.Assert(user.Login).Equal(getuser.Login)
|
||||
g.Assert(user.Token).Equal(getuser.Token)
|
||||
@ -94,7 +94,7 @@ func TestUsers(t *testing.T) {
|
||||
}
|
||||
s.CreateUser(&user)
|
||||
getuser, err := s.GetUserLogin(user.Login)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(user.ID).Equal(getuser.ID)
|
||||
g.Assert(user.Login).Equal(getuser.Login)
|
||||
})
|
||||
@ -112,8 +112,8 @@ func TestUsers(t *testing.T) {
|
||||
}
|
||||
err1 := s.CreateUser(&user1)
|
||||
err2 := s.CreateUser(&user2)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsFalse()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNotNil()
|
||||
})
|
||||
|
||||
g.It("Should Get a User List", func() {
|
||||
@ -130,7 +130,7 @@ func TestUsers(t *testing.T) {
|
||||
s.CreateUser(&user1)
|
||||
s.CreateUser(&user2)
|
||||
users, err := s.GetUserList()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(users)).Equal(2)
|
||||
g.Assert(users[0].Login).Equal(user1.Login)
|
||||
g.Assert(users[0].Email).Equal(user1.Email)
|
||||
@ -151,7 +151,7 @@ func TestUsers(t *testing.T) {
|
||||
s.CreateUser(&user1)
|
||||
s.CreateUser(&user2)
|
||||
count, err := s.GetUserCount()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
if s.driver != "postgres" {
|
||||
// we have to skip this check for postgres because it uses
|
||||
// an estimate which may not be updated.
|
||||
@ -161,7 +161,7 @@ func TestUsers(t *testing.T) {
|
||||
|
||||
g.It("Should Get a User Count Zero", func() {
|
||||
count, err := s.GetUserCount()
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(count).Equal(0)
|
||||
})
|
||||
|
||||
@ -175,9 +175,9 @@ func TestUsers(t *testing.T) {
|
||||
_, err1 := s.GetUser(user.ID)
|
||||
err2 := s.DeleteUser(&user)
|
||||
_, err3 := s.GetUser(user.ID)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(err3 == nil).IsFalse()
|
||||
g.Assert(err1).IsNil()
|
||||
g.Assert(err2).IsNil()
|
||||
g.Assert(err3).IsNotNil()
|
||||
})
|
||||
|
||||
g.It("Should get the Build feed for a User", func() {
|
||||
@ -237,7 +237,7 @@ func TestUsers(t *testing.T) {
|
||||
s.CreateBuild(build4)
|
||||
|
||||
builds, err := s.UserFeed(user)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(builds)).Equal(3)
|
||||
g.Assert(builds[0].FullName).Equal(repo2.FullName)
|
||||
g.Assert(builds[1].FullName).Equal(repo1.FullName)
|
||||
|
Loading…
Reference in New Issue
Block a user