This repository was archived by the owner on Jan 31, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathgocd_test.rb
More file actions
98 lines (76 loc) · 2.05 KB
/
Copy pathgocd_test.rb
File metadata and controls
98 lines (76 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require File.expand_path('../helper', __FILE__)
class GoCDTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
end
def test_push
end
def test_push_deleted_branch
@stubs.post "go/api/material/notify/git" do
assert false, "service should not be called for deleted branches"
end
svc = service :push, data, { "deleted" => true }
svc.receive
end
def test_requires_base_url
data = self.data.update("base_url" => "")
svc = service :push, data, payload
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_requires_repository_url
data = self.data.update("repository_url" => "")
svc = service :push, data, payload
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_failed_go_server
svc = service :push, data, payload
def svc.http_post(*args)
raise SocketError, "getaddrinfo: Name or service not known"
end
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_invalid_go_url
@stubs.post "go/api/material/notify/git" do
[404, {}, ""]
end
svc = service :push, data, payload
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_authorization_passed
@stubs.post "go/api/material/notify/git" do |env|
assert_equal basic_auth(:admin, :badger), env[:request_headers]['authorization']
[200, {}, ""]
end
svc = service :push, data, payload
svc.receive
end
def test_triggers_build
@stubs.post "go/api/material/notify/git" do |env|
assert_equal "localhost", env[:url].host
assert_equal 8153, env[:url].port
[200, {}, ""]
end
svc = service :push, data, payload
svc.receive
@stubs.verify_stubbed_calls
end
def data
{
"base_url" => "http://localhost:8153",
"repository_url" => "git://github.com/gocd/gocd",
"username" => "admin",
"password" => "badger"
}
end
def service(*args)
super Service::GoCD, *args
end
end