sr-bob-test 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +23 -0
- data/README.md +1 -0
- data/Rakefile +3 -0
- data/lib/bob/test.rb +4 -0
- data/lib/bob/test/buildable_stub.rb +38 -0
- data/lib/bob/test/scm/abstract.rb +66 -0
- data/lib/bob/test/scm/git.rb +48 -0
- data/lib/bob/test/scm/svn.rb +72 -0
- data/test/bob_test_test.rb +67 -0
- metadata +81 -0
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2009 Nicolás Sanguinetti <http://nicolassanguinetti.info>
|
2
|
+
Copyright (c) 2009 Simon Rozet <http://atonie.org>
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
See 4c8296ec4f50c92686e4fa9cd7006b4780a9ddbb for details.
|
data/Rakefile
ADDED
data/lib/bob/test.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Bob::Test
|
2
|
+
BuildableStub = Struct.new(:kind, :uri, :branch, :build_script) do
|
3
|
+
include Bob::Buildable
|
4
|
+
|
5
|
+
attr_reader :repo, :builds, :metadata
|
6
|
+
|
7
|
+
def self.from(repo)
|
8
|
+
kind = repo.class == Bob::Test::GitRepo ? :git : :svn
|
9
|
+
# same
|
10
|
+
uri =
|
11
|
+
if kind == :git
|
12
|
+
repo.path
|
13
|
+
else
|
14
|
+
"file://#{SvnRepo.server_root}/#{repo.name}"
|
15
|
+
end
|
16
|
+
# move to repo
|
17
|
+
branch = (kind == :git) ? "master" : ""
|
18
|
+
build_script = "./test"
|
19
|
+
|
20
|
+
new(kind, uri, branch, build_script)
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(*args)
|
24
|
+
super
|
25
|
+
|
26
|
+
@builds = {}
|
27
|
+
@metadata = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_building(commit_id, commit_info)
|
31
|
+
@metadata[commit_id] = commit_info
|
32
|
+
end
|
33
|
+
|
34
|
+
def finish_building(commit_id, status, output)
|
35
|
+
@builds[commit_id] = [status ? :successful : :failed, output]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Bob::Test
|
2
|
+
class AbstractSCMRepo
|
3
|
+
attr_reader :path, :name
|
4
|
+
|
5
|
+
def initialize(name, base_dir=Bob.directory)
|
6
|
+
@name = name
|
7
|
+
@path = File.join(base_dir, @name.to_s)
|
8
|
+
end
|
9
|
+
|
10
|
+
def destroy
|
11
|
+
FileUtils.rm_r path if File.directory?(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_commit(message, &action)
|
15
|
+
Dir.chdir(path) do
|
16
|
+
yield action
|
17
|
+
commit(message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_failing_commit
|
22
|
+
add_commit "This commit will fail" do
|
23
|
+
system "echo '#{build_script(false)}' > test"
|
24
|
+
system "chmod +x test"
|
25
|
+
add "test"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_successful_commit
|
30
|
+
add_commit "This commit will work" do
|
31
|
+
system "echo '#{build_script(true)}' > test"
|
32
|
+
system "chmod +x test"
|
33
|
+
add "test"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def commits
|
38
|
+
raise NotImplementedError
|
39
|
+
end
|
40
|
+
|
41
|
+
def head
|
42
|
+
commits.last[:identifier]
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
def add(file)
|
47
|
+
raise NotImplementedError
|
48
|
+
end
|
49
|
+
|
50
|
+
def commit(message)
|
51
|
+
raise NotImplementedError
|
52
|
+
end
|
53
|
+
|
54
|
+
def run(command)
|
55
|
+
system "#{command} &>/dev/null"
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_script(successful=true)
|
59
|
+
<<-script
|
60
|
+
#!/bin/sh
|
61
|
+
echo "Running tests..."
|
62
|
+
exit #{successful ? 0 : 1}
|
63
|
+
script
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/abstract"
|
2
|
+
|
3
|
+
module Bob::Test
|
4
|
+
class GitRepo < AbstractSCMRepo
|
5
|
+
def create
|
6
|
+
FileUtils.mkdir_p(path)
|
7
|
+
|
8
|
+
Dir.chdir(path) do
|
9
|
+
run "git init"
|
10
|
+
run "git config user.name 'John Doe'"
|
11
|
+
run "git config user.email 'johndoe@example.org'"
|
12
|
+
run "echo 'just a test repo' >> README"
|
13
|
+
add "README"
|
14
|
+
commit "First commit"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def commits
|
19
|
+
Dir.chdir(path) do
|
20
|
+
commits = `git log --pretty=oneline`.collect { |l| l.split(" ").first }
|
21
|
+
commits.inject([]) do |commits, sha1|
|
22
|
+
format = "---%n:message: >-%n %s%n:timestamp: %ci%n" +
|
23
|
+
":identifier: %H%n:author: %n :name: %an%n :email: %ae%n"
|
24
|
+
commits << YAML.load(`git show -s --pretty=format:"#{format}" #{sha1}`)
|
25
|
+
end.reverse
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def head
|
30
|
+
Dir.chdir(path) do
|
31
|
+
`git log --pretty=format:%H | head -1`.chomp
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def short_head
|
36
|
+
head[0..6]
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def add(file)
|
41
|
+
run "git add #{file}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def commit(message)
|
45
|
+
run %Q{git commit -m "#{message}"}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/abstract"
|
2
|
+
require "hpricot"
|
3
|
+
|
4
|
+
module Bob::Test
|
5
|
+
class SvnRepo < AbstractSCMRepo
|
6
|
+
def self.server_root
|
7
|
+
@root ||= File.join(Bob.directory, "svn")
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :remote
|
11
|
+
|
12
|
+
def initialize(name, base_dir=Bob.directory)
|
13
|
+
super
|
14
|
+
|
15
|
+
@path = File.join(base_dir, "svn-#{name}")
|
16
|
+
@remote = File.join(SvnRepo.server_root, name.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
create_remote
|
21
|
+
|
22
|
+
run "svn checkout file://#{remote} #{path}"
|
23
|
+
|
24
|
+
add_commit("First commit") do
|
25
|
+
run "echo 'just a test repo' >> README"
|
26
|
+
add "README"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroy
|
31
|
+
FileUtils.rm_r(remote) if File.directory?(remote)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def commits
|
36
|
+
Dir.chdir(path) do
|
37
|
+
doc = Hpricot::XML(`svn log --xml`)
|
38
|
+
|
39
|
+
(doc/:log/:logentry).inject([]) { |commits, commit|
|
40
|
+
commits << { :identifier => commit["revision"],
|
41
|
+
:message => commit.at("msg").inner_html,
|
42
|
+
:committed_at => Time.parse(commit.at("date").inner_html) }
|
43
|
+
}.reverse
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method :short_head, :head
|
48
|
+
|
49
|
+
protected
|
50
|
+
def add(file)
|
51
|
+
run "svn add #{file}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def commit(message)
|
55
|
+
run %Q{svn commit -m "#{message}"}
|
56
|
+
run "svn up"
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def create_remote
|
61
|
+
FileUtils.mkdir_p(SvnRepo.server_root)
|
62
|
+
|
63
|
+
run "svnadmin create #{remote}"
|
64
|
+
|
65
|
+
File.open(File.join(remote, "conf", "svnserve.conf"), "w") { |f|
|
66
|
+
f.puts "[general]"
|
67
|
+
f.puts "anon-access = write"
|
68
|
+
f.puts "auth-access = write"
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "bob/test"
|
3
|
+
|
4
|
+
class BobTestTest < Test::Unit::TestCase
|
5
|
+
include Bob::Test
|
6
|
+
|
7
|
+
def assert_scm_repo(repo)
|
8
|
+
repo.destroy
|
9
|
+
repo.create
|
10
|
+
|
11
|
+
assert_equal 1, repo.commits.size
|
12
|
+
assert_equal "First commit", repo.commits.first[:message]
|
13
|
+
|
14
|
+
repo.add_failing_commit
|
15
|
+
assert_equal 2, repo.commits.size
|
16
|
+
assert_equal "This commit will fail", repo.commits.last[:message]
|
17
|
+
assert_equal repo.commits.last[:identifier], repo.head
|
18
|
+
assert repo.short_head
|
19
|
+
|
20
|
+
repo.add_successful_commit
|
21
|
+
assert_equal 3, repo.commits.size
|
22
|
+
assert_equal "This commit will work", repo.commits.last[:message]
|
23
|
+
assert_equal repo.commits.last[:identifier], repo.head
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_buildable_stub
|
27
|
+
b = BuildableStub.new(:git, "git://github.com/ry/node", "master", "make")
|
28
|
+
|
29
|
+
assert_equal :git, b.kind
|
30
|
+
assert_equal "git://github.com/ry/node", b.uri
|
31
|
+
assert_equal "master", b.branch
|
32
|
+
assert_equal "make", b.build_script
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_scm_repo
|
36
|
+
assert_scm_repo(GitRepo.new(:my_test_project))
|
37
|
+
assert_scm_repo(SvnRepo.new(:my_test_project))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_buildable_git_repo
|
41
|
+
Bob.directory = "/tmp/bob-git"
|
42
|
+
|
43
|
+
repo = GitRepo.new(:test_repo)
|
44
|
+
repo.destroy
|
45
|
+
repo.create
|
46
|
+
|
47
|
+
b = BuildableStub.from(repo)
|
48
|
+
assert_equal :git, b.kind
|
49
|
+
assert_equal "/tmp/bob-git/test_repo", b.uri
|
50
|
+
assert_equal "master", b.branch
|
51
|
+
assert_equal "./test", b.build_script
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_buildable_svn_repo
|
55
|
+
Bob.directory = "/tmp/bob-svn"
|
56
|
+
|
57
|
+
repo = SvnRepo.new(:test_repo)
|
58
|
+
repo.destroy
|
59
|
+
repo.create
|
60
|
+
|
61
|
+
b = BuildableStub.from(repo)
|
62
|
+
assert_equal :svn, b.kind
|
63
|
+
assert_equal "", b.branch
|
64
|
+
assert_equal "./test", b.build_script
|
65
|
+
assert_equal "file:///tmp/bob-svn/svn/test_repo", b.uri
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sr-bob-test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Nicol\xC3\xA1s Sanguinetti"
|
8
|
+
- Simon Rozet
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-06-01 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bob-the-builder
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hpricot
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
version:
|
36
|
+
description: test helpers for bob etc
|
37
|
+
email: info@integrityapp.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/bob/test.rb
|
49
|
+
- lib/bob/test/buildable_stub.rb
|
50
|
+
- lib/bob/test/scm/abstract.rb
|
51
|
+
- lib/bob/test/scm/git.rb
|
52
|
+
- lib/bob/test/scm/svn.rb
|
53
|
+
- test/bob_test_test.rb
|
54
|
+
has_rdoc: false
|
55
|
+
homepage: http://integrityapp.com
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project: integrity
|
76
|
+
rubygems_version: 1.2.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 2
|
79
|
+
summary: test helpers for bob etc
|
80
|
+
test_files: []
|
81
|
+
|