mirror of
https://github.com/zhigang1992/actions.git
synced 2026-01-12 08:53:47 +08:00
Merge pull request #16 from unacast/add_tests
Initial attempt at BATS tests
This commit is contained in:
@@ -12,7 +12,7 @@ lint: shell-lint docker-lint ## Lint all of the files for this Action.
|
||||
build: docker-build ## Build this Action.
|
||||
|
||||
.PHONY: test
|
||||
test: ## Test the components of this Action.
|
||||
test: shell-test ## Test the components of this Action.
|
||||
|
||||
.PHONY: publish
|
||||
publish: docker-publish ## Publish this Action.
|
||||
publish: docker-publish ## Publish this Action.
|
||||
|
||||
27
github-deploy/test/deployment-get-id.bats
Normal file
27
github-deploy/test/deployment-get-id.bats
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
#load bootstrap
|
||||
|
||||
PATH="$PATH:$BATS_TEST_DIRNAME/../bin"
|
||||
|
||||
export GITHUB_EVENT_PATH="$BATS_TEST_DIRNAME/fixtures/deployment.json"
|
||||
|
||||
@test "returns deployment id and $? = 0 deployment event" {
|
||||
run deployment-get-id
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "87972451" ]
|
||||
}
|
||||
|
||||
@test "returns error code when GITHUB_EVENT_PATH not set" {
|
||||
skip "this probably does not have the right behaviour?"
|
||||
unset GITHUB_EVENT_PATH
|
||||
run deployment-get-id
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "returns error code on other event than deployment" {
|
||||
export GITHUB_EVENT_PATH="$BATS_TEST_DIRNAME/fixtures/pull_request_event.json"
|
||||
run deployment-get-id
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "" ]
|
||||
}
|
||||
25
github-deploy/test/deployment-get-payload.bats
Normal file
25
github-deploy/test/deployment-get-payload.bats
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
#load bootstrap
|
||||
|
||||
PATH="$PATH:$BATS_TEST_DIRNAME/../bin"
|
||||
|
||||
export GITHUB_EVENT_PATH="$BATS_TEST_DIRNAME/fixtures/deployment.json"
|
||||
|
||||
@test "return error code if not given a parameter" {
|
||||
run deployment-get-payload
|
||||
[ "$status" -eq 64 ]
|
||||
}
|
||||
|
||||
@test "returns correct payload item" {
|
||||
run deployment-get-payload test_payload
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "value" ]
|
||||
}
|
||||
|
||||
|
||||
@test "returns empty string if payload does not exist" {
|
||||
run deployment-get-payload foo_payload
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "" ]
|
||||
}
|
||||
11
github-deploy/test/deployment-get-task.bats
Normal file
11
github-deploy/test/deployment-get-task.bats
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
PATH="$PATH:$BATS_TEST_DIRNAME/../bin"
|
||||
|
||||
export GITHUB_EVENT_PATH="$BATS_TEST_DIRNAME/fixtures/deployment.json"
|
||||
|
||||
@test "returs deployment task" {
|
||||
run deployment-get-task
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "deploy" ]
|
||||
}
|
||||
154
github-deploy/test/fixtures/deployment.json
vendored
Normal file
154
github-deploy/test/fixtures/deployment.json
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
{
|
||||
"deployment": {
|
||||
"url": "https://api.github.com/repos/Codertocat/Hello-World/deployments/87972451",
|
||||
"id": 87972451,
|
||||
"node_id": "MDEwOkRlcGxveW1lbnQ4Nzk3MjQ1MQ==",
|
||||
"sha": "a10867b14bb761a232cd80139fbd4c0d33264240",
|
||||
"ref": "master",
|
||||
"task": "deploy",
|
||||
"payload": {
|
||||
"config": {
|
||||
"test_payload": "value"
|
||||
}
|
||||
},
|
||||
"environment": "production",
|
||||
"description": null,
|
||||
"creator": {
|
||||
"login": "Codertocat",
|
||||
"id": 21031067,
|
||||
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/Codertocat",
|
||||
"html_url": "https://github.com/Codertocat",
|
||||
"followers_url": "https://api.github.com/users/Codertocat/followers",
|
||||
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
|
||||
"repos_url": "https://api.github.com/users/Codertocat/repos",
|
||||
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
},
|
||||
"created_at": "2018-05-30T20:18:45Z",
|
||||
"updated_at": "2018-05-30T20:18:45Z",
|
||||
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments/87972451/statuses",
|
||||
"repository_url": "https://api.github.com/repos/Codertocat/Hello-World"
|
||||
},
|
||||
"repository": {
|
||||
"id": 135493233,
|
||||
"node_id": "MDEwOlJlcG9zaXRvcnkxMzU0OTMyMzM=",
|
||||
"name": "Hello-World",
|
||||
"full_name": "Codertocat/Hello-World",
|
||||
"owner": {
|
||||
"login": "Codertocat",
|
||||
"id": 21031067,
|
||||
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/Codertocat",
|
||||
"html_url": "https://github.com/Codertocat",
|
||||
"followers_url": "https://api.github.com/users/Codertocat/followers",
|
||||
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
|
||||
"repos_url": "https://api.github.com/users/Codertocat/repos",
|
||||
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
},
|
||||
"private": false,
|
||||
"html_url": "https://github.com/Codertocat/Hello-World",
|
||||
"description": null,
|
||||
"fork": false,
|
||||
"url": "https://api.github.com/repos/Codertocat/Hello-World",
|
||||
"forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks",
|
||||
"keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}",
|
||||
"collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}",
|
||||
"teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams",
|
||||
"hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks",
|
||||
"issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}",
|
||||
"events_url": "https://api.github.com/repos/Codertocat/Hello-World/events",
|
||||
"assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}",
|
||||
"branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}",
|
||||
"tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags",
|
||||
"blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}",
|
||||
"git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}",
|
||||
"git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}",
|
||||
"trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}",
|
||||
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}",
|
||||
"languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages",
|
||||
"stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers",
|
||||
"contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors",
|
||||
"subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers",
|
||||
"subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription",
|
||||
"commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}",
|
||||
"git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}",
|
||||
"comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}",
|
||||
"issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}",
|
||||
"contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}",
|
||||
"compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}",
|
||||
"merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges",
|
||||
"archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}",
|
||||
"downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads",
|
||||
"issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}",
|
||||
"pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}",
|
||||
"milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}",
|
||||
"notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}",
|
||||
"labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}",
|
||||
"releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}",
|
||||
"deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments",
|
||||
"created_at": "2018-05-30T20:18:04Z",
|
||||
"updated_at": "2018-05-30T20:18:35Z",
|
||||
"pushed_at": "2018-05-30T20:18:44Z",
|
||||
"git_url": "git://github.com/Codertocat/Hello-World.git",
|
||||
"ssh_url": "git@github.com:Codertocat/Hello-World.git",
|
||||
"clone_url": "https://github.com/Codertocat/Hello-World.git",
|
||||
"svn_url": "https://github.com/Codertocat/Hello-World",
|
||||
"homepage": null,
|
||||
"size": 0,
|
||||
"stargazers_count": 0,
|
||||
"watchers_count": 0,
|
||||
"language": null,
|
||||
"has_issues": true,
|
||||
"has_projects": true,
|
||||
"has_downloads": true,
|
||||
"has_wiki": true,
|
||||
"has_pages": true,
|
||||
"forks_count": 0,
|
||||
"mirror_url": null,
|
||||
"archived": false,
|
||||
"open_issues_count": 2,
|
||||
"license": null,
|
||||
"forks": 0,
|
||||
"open_issues": 2,
|
||||
"watchers": 0,
|
||||
"default_branch": "master"
|
||||
},
|
||||
"sender": {
|
||||
"login": "Codertocat",
|
||||
"id": 21031067,
|
||||
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/Codertocat",
|
||||
"html_url": "https://github.com/Codertocat",
|
||||
"followers_url": "https://api.github.com/users/Codertocat/followers",
|
||||
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
|
||||
"repos_url": "https://api.github.com/users/Codertocat/repos",
|
||||
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
}
|
||||
}
|
||||
17
github-deploy/test/fixtures/pull_request_event.json
vendored
Normal file
17
github-deploy/test/fixtures/pull_request_event.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"action": "closed",
|
||||
"pull_request": {
|
||||
"merged": "false",
|
||||
"labels": [
|
||||
{
|
||||
"name": "urgent"
|
||||
},
|
||||
{
|
||||
"name": "bug"
|
||||
}
|
||||
],
|
||||
"user": {
|
||||
"login": "pr-user"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user