Skip to content

Commit

Permalink
Testing event_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Kysow committed Nov 16, 2017
1 parent 6258957 commit bb4798f
Showing 1 changed file with 91 additions and 2 deletions.
93 changes: 91 additions & 2 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
. "github.com/hootsuite/atlantis/server/events/vcs/fixtures"
. "github.com/hootsuite/atlantis/testing"
"github.com/mohae/deepcopy"
"github.com/lkysow/go-gitlab"
"encoding/json"
)

var parser = events.EventParser{
Expand Down Expand Up @@ -239,7 +241,7 @@ func TestParseGithubPull(t *testing.T) {
_, _, err = parser.ParseGithubPull(&testPull)
Equals(t, errors.New("repository.full_name is null"), err)

PullRes, repoRes, err := parser.ParseGithubPull(&Pull)
pullRes, repoRes, err := parser.ParseGithubPull(&Pull)
Ok(t, err)
Equals(t, models.PullRequest{
URL: Pull.GetHTMLURL(),
Expand All @@ -248,7 +250,7 @@ func TestParseGithubPull(t *testing.T) {
HeadCommit: Pull.Head.GetSHA(),
Num: Pull.GetNumber(),
State: models.Open,
}, PullRes)
}, pullRes)

Equals(t, models.Repo{
Owner: "owner",
Expand All @@ -259,6 +261,15 @@ func TestParseGithubPull(t *testing.T) {
}, repoRes)
}

func TestParseGitlabMergeEvent(t *testing.T) {
t.Log("should properly parse a gitlab merge event")
var event *gitlab.MergeEvent
err := json.Unmarshal([]byte(mergeEventJSON), &event)
Ok(t, err)
pull, repo := parser.ParseGitlabMergeEvent(*event)
Equals(t, mo)
}

func containsVerbose(list []string) bool {
for _, b := range list {
if b == "--verbose" {
Expand All @@ -267,3 +278,81 @@ func containsVerbose(list []string) bool {
}
return false
}

var mergeEventJSON = `{
"object_kind": "merge_request",
"user": {
"name": "Administrator",
"username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
},
"object_attributes": {
"id": 99,
"target_branch": "master",
"source_branch": "ms-viewport",
"source_project_id": 14,
"author_id": 51,
"assignee_id": 6,
"title": "MS-Viewport",
"created_at": "2013-12-03T17:23:34Z",
"updated_at": "2013-12-03T17:23:34Z",
"st_commits": null,
"st_diffs": null,
"milestone_id": null,
"state": "opened",
"merge_status": "unchecked",
"target_project_id": 14,
"iid": 1,
"description": "",
"source":{
"name":"Awesome Project",
"description":"Aut reprehenderit ut est.",
"web_url":"http://example.com/awesome_space/awesome_project",
"avatar_url":null,
"git_ssh_url":"git@example.com:awesome_space/awesome_project.git",
"git_http_url":"http://example.com/awesome_space/awesome_project.git",
"namespace":"Awesome Space",
"visibility":"private",
"path_with_namespace":"awesome_space/awesome_project",
"default_branch":"master",
"homepage":"http://example.com/awesome_space/awesome_project",
"url":"http://example.com/awesome_space/awesome_project.git",
"ssh_url":"git@example.com:awesome_space/awesome_project.git",
"http_url":"http://example.com/awesome_space/awesome_project.git"
},
"target": {
"name":"Awesome Project",
"description":"Aut reprehenderit ut est.",
"web_url":"http://example.com/awesome_space/awesome_project",
"avatar_url":null,
"git_ssh_url":"git@example.com:awesome_space/awesome_project.git",
"git_http_url":"http://example.com/awesome_space/awesome_project.git",
"namespace":"Awesome Space",
"visibility":"private",
"path_with_namespace":"awesome_space/awesome_project",
"default_branch":"master",
"homepage":"http://example.com/awesome_space/awesome_project",
"url":"http://example.com/awesome_space/awesome_project.git",
"ssh_url":"git@example.com:awesome_space/awesome_project.git",
"http_url":"http://example.com/awesome_space/awesome_project.git"
},
"last_commit": {
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev@dv6700.(none)"
}
},
"work_in_progress": false,
"url": "http://example.com/diaspora/merge_requests/1",
"action": "open",
"assignee": {
"name": "User1",
"username": "user1",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
}
}
}`

0 comments on commit bb4798f

Please sign in to comment.