Testing author label length limitation.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-08-13 14:07:45 +08:00
parent e82ddd0022
commit 83056ab8b3
3 changed files with 59 additions and 65 deletions

View file

@ -67,11 +67,10 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
name := refParts[2] name := refParts[2]
commitType := refParts[1] commitType := refParts[1]
//Ensuring the author label is not longer then 40 for the label of the commit author (default size in the db) //Ensuring the author label is not longer then 40 for the label of the commit author (default size in the db)
authorLabel := hook.Changesets.Values[0].ToCommit.Author.Name authorLabel := hook.Changesets.Values[0].ToCommit.Author.Name
if (len(authorLabel) > 40) { if len(authorLabel) > 40 {
authorLabel = authorLabel[0:40] authorLabel = authorLabel[0:37] + "..."
} }
build := &model.Build{ build := &model.Build{

View file

@ -1,12 +1,11 @@
package bitbucketserver package bitbucketserver
import ( import (
"testing"
"github.com/drone/drone/model" "github.com/drone/drone/model"
"github.com/drone/drone/remote/bitbucketserver/internal" "github.com/drone/drone/remote/bitbucketserver/internal"
"github.com/franela/goblin" "github.com/franela/goblin"
"github.com/mrjones/oauth" "github.com/mrjones/oauth"
"testing"
) )
func Test_helper(t *testing.T) { func Test_helper(t *testing.T) {
@ -14,7 +13,6 @@ func Test_helper(t *testing.T) {
g := goblin.Goblin(t) g := goblin.Goblin(t)
g.Describe("Bitbucket Server converter", func() { g.Describe("Bitbucket Server converter", func() {
g.It("should convert repository lite", func() { g.It("should convert repository lite", func() {
from := &internal.Repo{} from := &internal.Repo{}
from.Project.Key = "octocat" from.Project.Key = "octocat"
@ -26,7 +24,6 @@ func Test_helper(t *testing.T) {
g.Assert(to.Name).Equal("hello-world") g.Assert(to.Name).Equal("hello-world")
}) })
g.It("should convert repository", func() { g.It("should convert repository", func() {
from := &internal.Repo{ from := &internal.Repo{
Slug: "hello-world", Slug: "hello-world",
@ -72,8 +69,6 @@ func Test_helper(t *testing.T) {
g.Assert(result.Token).Equal("foo") g.Assert(result.Token).Equal("foo")
}) })
g.It("should convert push hook to build", func() { g.It("should convert push hook to build", func() {
change := internal.PostHook{} change := internal.PostHook{}
@ -83,7 +78,7 @@ func Test_helper(t *testing.T) {
}) })
value := internal.Value{} value := internal.Value{}
value.ToCommit.Author.Name = "John Doe" value.ToCommit.Author.Name = "John Doe, Appleboy, Mary, Janet E. Dawson and Ann S. Palmer"
value.ToCommit.Author.EmailAddress = "huh@huh.com" value.ToCommit.Author.EmailAddress = "huh@huh.com"
value.ToCommit.Message = "message" value.ToCommit.Message = "message"
@ -94,7 +89,8 @@ func Test_helper(t *testing.T) {
build := convertPushHook(&change, "http://base.com") build := convertPushHook(&change, "http://base.com")
g.Assert(build.Event).Equal(model.EventPush) g.Assert(build.Event).Equal(model.EventPush)
g.Assert(build.Author).Equal("John Doe") // Ensuring the author label is not longer then 40
g.Assert(build.Author).Equal("John Doe, Appleboy, Mary, Janet E. Da...")
g.Assert(build.Avatar).Equal(avatarLink("huh@huh.com")) g.Assert(build.Avatar).Equal(avatarLink("huh@huh.com"))
g.Assert(build.Commit).Equal("73f9c44d") g.Assert(build.Commit).Equal("73f9c44d")
g.Assert(build.Branch).Equal("master") g.Assert(build.Branch).Equal("master")

View file

@ -28,7 +28,7 @@ type Repo struct {
Forkable bool `json:"forkable"` Forkable bool `json:"forkable"`
ID int `json:"id"` ID int `json:"id"`
Links struct { Links struct {
Clone []CloneLink`json:"clone"` Clone []CloneLink `json:"clone"`
Self []struct { Self []struct {
Href string `json:"href"` Href string `json:"href"`
} `json:"self"` } `json:"self"`
@ -125,7 +125,6 @@ type Value struct {
} `json:"toCommit"` } `json:"toCommit"`
} }
type PostHook struct { type PostHook struct {
Changesets struct { Changesets struct {
Filter interface{} `json:"filter"` Filter interface{} `json:"filter"`