git-ds 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.rdoc +795 -0
  2. data/doc/Examples.rdoc +36 -0
  3. data/doc/examples/key_value/kv_get.rb +29 -0
  4. data/doc/examples/key_value/kv_init.rb +20 -0
  5. data/doc/examples/key_value/kv_list.rb +28 -0
  6. data/doc/examples/key_value/kv_remove.rb +29 -0
  7. data/doc/examples/key_value/kv_set.rb +39 -0
  8. data/doc/examples/key_value/model.rb +156 -0
  9. data/doc/examples/key_value/test.rb +50 -0
  10. data/doc/examples/test_suite/model.rb +503 -0
  11. data/doc/examples/test_suite/test.rb +173 -0
  12. data/doc/examples/test_suite/ts_add_bug.rb +65 -0
  13. data/doc/examples/test_suite/ts_add_module.rb +74 -0
  14. data/doc/examples/test_suite/ts_add_module_to_test.rb +78 -0
  15. data/doc/examples/test_suite/ts_add_test.rb +77 -0
  16. data/doc/examples/test_suite/ts_add_test_suite.rb +65 -0
  17. data/doc/examples/test_suite/ts_add_test_to_bug.rb +76 -0
  18. data/doc/examples/test_suite/ts_init.rb +20 -0
  19. data/doc/examples/test_suite/ts_list.rb +118 -0
  20. data/doc/examples/test_suite/ts_perform_test.rb +104 -0
  21. data/doc/examples/test_suite/ts_update_bugs.rb +58 -0
  22. data/doc/examples/user_group/model.rb +265 -0
  23. data/doc/examples/user_group/test.rb +64 -0
  24. data/doc/examples/user_group/ug_add_group.rb +39 -0
  25. data/doc/examples/user_group/ug_add_group_user.rb +36 -0
  26. data/doc/examples/user_group/ug_add_user.rb +39 -0
  27. data/doc/examples/user_group/ug_init.rb +20 -0
  28. data/doc/examples/user_group/ug_list.rb +32 -0
  29. data/lib/git-ds.rb +14 -0
  30. data/lib/git-ds/config.rb +53 -0
  31. data/lib/git-ds/database.rb +289 -0
  32. data/lib/git-ds/exec_cmd.rb +107 -0
  33. data/lib/git-ds/index.rb +205 -0
  34. data/lib/git-ds/model.rb +136 -0
  35. data/lib/git-ds/model/db_item.rb +42 -0
  36. data/lib/git-ds/model/fs_item.rb +51 -0
  37. data/lib/git-ds/model/item.rb +428 -0
  38. data/lib/git-ds/model/item_list.rb +97 -0
  39. data/lib/git-ds/model/item_proxy.rb +128 -0
  40. data/lib/git-ds/model/property.rb +144 -0
  41. data/lib/git-ds/model/root.rb +46 -0
  42. data/lib/git-ds/repo.rb +455 -0
  43. data/lib/git-ds/shared.rb +17 -0
  44. data/lib/git-ds/transaction.rb +77 -0
  45. data/tests/ut_database.rb +304 -0
  46. data/tests/ut_git_grit_equiv.rb +195 -0
  47. data/tests/ut_index.rb +203 -0
  48. data/tests/ut_model.rb +360 -0
  49. data/tests/ut_repo.rb +260 -0
  50. data/tests/ut_user_group_model.rb +316 -0
  51. metadata +142 -0
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the TestSuite database example
3
+ # Copyright 2011 Thoughtgang <http://www.thoughtgang.org>
4
+
5
+ BASE=File.dirname(File.expand_path(__FILE__)\
6
+ ).split(File::SEPARATOR)[0..-4].join(File::SEPARATOR)
7
+ $: << BASE + File::SEPARATOR + 'lib'
8
+ $: << BASE + File::SEPARATOR + 'doc' + File::SEPARATOR + 'examples'
9
+
10
+ require 'test_suite/ts_list'
11
+
12
+ # ----------------------------------------------------------------------
13
+
14
+ def fill_model(model)
15
+
16
+ modules = {
17
+ 'projects/thing/include/thing.h' => "void thing();\n" ,
18
+ 'projects/thing/include/arch/arm.h' => "#define ARM\n" ,
19
+ 'projects/thing/include/arch/x86.h' => "#define X86\n" ,
20
+ 'projects/thing/src/thing.c' => "void thing() { /* nop */ }\n" ,
21
+ 'projects/thing/src/ops.c' => "void ops(){ /* nop */ }\n" ,
22
+ 'projects/thing/src/util.c' => "void util() { /* nop */ }\n" ,
23
+ 'projects/shared/libstuff/include/stuff.h' => "int stuff();" ,
24
+ 'projects/shared/libstuff/src/stuff.c' => "int stuff() { return 1; }"
25
+ }
26
+
27
+ test_suites = {
28
+ 'Development' => { :description => 'Performed during active development',
29
+ :tests => {
30
+ 'thing_thing' => [
31
+ 'projects.thing.include.thing.h',
32
+ 'projects.thing.src.thing.c'
33
+ ],
34
+ 'thing_arm' => [
35
+ 'projects.thing.include.arch.arm.h',
36
+ 'projects.thing.include.thing.h',
37
+ 'projects.thing.src.thing.c'
38
+ ],
39
+ 'thing_x86' => [
40
+ 'projects.thing.include.arch.x86.h',
41
+ 'projects.thing.include.thing.h',
42
+ 'projects.thing.src.thing.c'
43
+ ],
44
+ 'thing_ops' => [ 'projects.thing.src.ops.c' ],
45
+ 'thing_util' => [ 'projects.thing.src.util.c' ]
46
+ } },
47
+ 'QA' => { :description => 'Performed by QA department',
48
+ :tests => {
49
+ 'thing_regression' => [
50
+ 'projects.thing.src.thing.c',
51
+ 'projects.thing.src.ops.c',
52
+ 'projects.thing.src.util.c',
53
+ 'projects.thing.include.thing.h'
54
+ ],
55
+ 'stuff_regression' => [
56
+ 'projects.shared.libstuff.include.stuff.h',
57
+ 'projects.shared.libstuff.src.stuff.c'
58
+ ]
59
+ } },
60
+ 'Release' => { :description => 'Performed on a release candidate',
61
+ :tests => {
62
+ 'thing_integration' => [
63
+ 'projects.thing.src.thing.c',
64
+ 'projects.thing.src.ops.c',
65
+ 'projects.thing.src.util.c',
66
+ 'projects.thing.include.thing.h'
67
+ ],
68
+ 'stuff_integration' => [
69
+ 'projects.shared.libstuff.include.stuff.h',
70
+ 'projects.shared.libstuff.src.stuff.c'
71
+ ]
72
+ } }
73
+ }
74
+
75
+ bugs = {
76
+ 1200 => { :description => 'Thing calculates wrong value',
77
+ :tests => [
78
+ ['Development', 'thing_thing'],
79
+ ['QA', 'thing_regression'],
80
+ ['Release', 'thing_integration']
81
+ ] },
82
+ 1201 => { :description => 'Memory leak in stuff',
83
+ :tests => [
84
+ ['QA', 'stuff_regression'],
85
+ ['Release', 'stuff_integration']
86
+ ] },
87
+ 1202 => { :description => 'SEGV in thing',
88
+ :tests => [
89
+ ['Development', 'thing_thing'],
90
+ ['Development', 'thing_util'],
91
+ ['QA', 'thing_regression']
92
+ ] },
93
+ 'v1-user-nologin' => { :description => 'User cannot log in (Version 1)',
94
+ :tests => [ ['Release', 'thing_integration'] ] }
95
+ }
96
+
97
+ modules.each do |path, data|
98
+ model.add_module(path, data)
99
+ end
100
+
101
+ test_suites.each do |name, h|
102
+ s = model.add_test_suite(name, h[:description])
103
+ h[:tests].each do |name, arr|
104
+ mods = arr.inject([]) { |arr, ident| arr << model.module(ident) }
105
+ s.add_test(name, mods)
106
+ end
107
+ end
108
+
109
+ bugs.each do |name, h|
110
+ b = model.add_bug(name, h[:description])
111
+ h[:tests].each do |arr|
112
+ s = model.test_suite(arr[0])
113
+ t = s.test(arr[1])
114
+ b.add_test(t)
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ def run_tests(db_path)
121
+ db = GitDS::Database.connect_as(db_path, 'tony b', 'tony@disco.net')
122
+ raise "Could not connect to db!" if not db
123
+
124
+ model = TestSuiteModel.new(db)
125
+ model.branched_transaction('TonyTesting') {
126
+ model.perform_tests { |t| t.perform(true) }
127
+ model.update_bugs
128
+ }
129
+ db.mark('Tony testing complete')
130
+ db.close
131
+
132
+ db = GitDS::Database.connect_as(db_path, 'bill p', 'bill@stallynz.net')
133
+ raise "Could not connect to db!" if not db
134
+
135
+ model = TestSuiteModel.new(db)
136
+ db.unstage
137
+ model.branched_transaction('QATesting') {
138
+ s = model.test_suite('QA')
139
+ s.tests.each do |ident|
140
+ t = s.test(ident)
141
+ t.perform(false, 'QA deemed results unworthy')
142
+ end
143
+ model.update_bugs
144
+ }
145
+ db.mark('QA testing complete')
146
+ db.close
147
+ end
148
+
149
+ # ----------------------------------------------------------------------
150
+ def list_model(model)
151
+ list_modules(model, true)
152
+ list_suites(model, true)
153
+ list_bugs(model, true)
154
+ end
155
+
156
+ # ----------------------------------------------------------------------
157
+ if __FILE__ == $0
158
+ path = (ARGV.count > 0) ? ARGV.shift : 'ts_test.db'
159
+
160
+ db = GitDS::Database.connect(path, true)
161
+ model = TestSuiteModel.new(db) if db
162
+ raise "Could not connect to model" if not model
163
+
164
+ model.branched_transaction('FillModel') do
165
+ fill_model(model)
166
+ end
167
+ db.mark('Initial data input')
168
+
169
+ run_tests(path)
170
+
171
+ list_model(model)
172
+ end
173
+
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # Add a Bug to a TestSuite database repo
3
+ # Copyright 2011 Thoughtgang <http://www.thoughtgang.org>
4
+
5
+ # Add examples dir and lib/git-ds to ruby path
6
+ BASE=File.dirname(File.expand_path(__FILE__)\
7
+ ).split(File::SEPARATOR)[0..-4].join(File::SEPARATOR)
8
+ $: << BASE + File::SEPARATOR + 'lib'
9
+ $: << BASE + File::SEPARATOR + 'doc' + File::SEPARATOR + 'examples'
10
+
11
+ require 'test_suite/model'
12
+ require 'optparse'
13
+ require 'ostruct'
14
+
15
+ def get_options(args)
16
+ options = OpenStruct.new
17
+
18
+ options.db = nil
19
+ options.auto = false
20
+ options.ident = nil
21
+ options.descr = nil
22
+
23
+ opts = OptionParser.new do |opts|
24
+ opts.banner = "Usage: #{$0} [-p db_path] IDENT DESCR"
25
+ opts.separator 'Add a bug report to database'
26
+ opts.separator 'Options:'
27
+
28
+ opts.on( '-p', '--db-path PATH', 'Path to TestSuite GitDS' ) do |path|
29
+ options.db = path
30
+ options.auto = true
31
+ end
32
+
33
+ opts.on_tail( '-?', '--help', 'Show this message') do
34
+ puts opts
35
+ exit -1
36
+ end
37
+ end
38
+
39
+ opts.parse!(args)
40
+
41
+ options.db = GitDS::Database.top_level if not options.db
42
+ raise "Invalid database" if not options.db
43
+
44
+ if args.count > 1
45
+ options.ident = args.shift
46
+ options.descr = args.shift
47
+ else
48
+ puts opts.banner
49
+ exit -2
50
+ end
51
+
52
+ options
53
+ end
54
+
55
+ # ----------------------------------------------------------------------
56
+ if __FILE__ == $0
57
+ options = get_options(ARGV)
58
+
59
+ model = TestSuiteModel.new(GitDS::Database.connect(options.db, options.auto))
60
+ raise "Could not connect to Model!" if not model
61
+
62
+ model.add_bug(options.ident, options.descr)
63
+
64
+ exit 0
65
+ end
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # Add a Module (file) to a TestSuite database repo
3
+ # Copyright 2011 Thoughtgang <http://www.thoughtgang.org>
4
+
5
+ # Add examples dir and lib/git-ds to ruby path
6
+ BASE=File.dirname(File.expand_path(__FILE__)\
7
+ ).split(File::SEPARATOR)[0..-4].join(File::SEPARATOR)
8
+ $: << BASE + File::SEPARATOR + 'lib'
9
+ $: << BASE + File::SEPARATOR + 'doc' + File::SEPARATOR + 'examples'
10
+
11
+ require 'test_suite/model'
12
+ require 'optparse'
13
+ require 'ostruct'
14
+
15
+ def get_options(args)
16
+ options = OpenStruct.new
17
+
18
+ options.db = nil
19
+ options.auto = false
20
+ options.path = nil
21
+ options.data = nil
22
+
23
+ opts = OptionParser.new do |opts|
24
+ opts.banner = "Usage: #{$0} [-p db_path] [-d data] MODULE_PATH"
25
+ opts.separator 'Add a module (source code file) to database'
26
+ opts.separator 'Options:'
27
+
28
+ opts.on( '-p', '--db-path PATH', 'Path to TestSuite GitDS' ) do |path|
29
+ options.db = path
30
+ options.auto = true
31
+ end
32
+
33
+ opts.on( '-d', '--data=STR', 'Contents of module' ) do |str|
34
+ options.data = str
35
+ end
36
+
37
+ opts.on_tail( '-?', '--help', 'Show this message') do
38
+ puts opts
39
+ exit -1
40
+ end
41
+ end
42
+
43
+ opts.parse!(args)
44
+
45
+ options.db = GitDS::Database.top_level if not options.db
46
+ raise "Invalid database" if not options.db
47
+
48
+ if args.count > 0
49
+ options.path = args.shift
50
+ if not options.data
51
+ options.data = File.exist?(options.path) ?
52
+ (File.open(options.path){ |f| f.read }) : nil
53
+ end
54
+ else
55
+ puts opts.banner
56
+ exit -2
57
+ end
58
+
59
+ raise "No data available for module '#{options.path}'" if not options.data
60
+
61
+ options
62
+ end
63
+
64
+ # ----------------------------------------------------------------------
65
+ if __FILE__ == $0
66
+ options = get_options(ARGV)
67
+
68
+ model = TestSuiteModel.new(GitDS::Database.connect(options.db, options.auto))
69
+ raise "Could not connect to Model!" if not model
70
+
71
+ model.add_module(options.path, options.data)
72
+
73
+ exit 0
74
+ end
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+ # Add a Module to a Test in a TestSuite database repo
3
+ # Copyright 2011 Thoughtgang <http://www.thoughtgang.org>
4
+
5
+ # Add examples dir and lib/git-ds to ruby path
6
+ BASE=File.dirname(File.expand_path(__FILE__)\
7
+ ).split(File::SEPARATOR)[0..-4].join(File::SEPARATOR)
8
+ $: << BASE + File::SEPARATOR + 'lib'
9
+ $: << BASE + File::SEPARATOR + 'doc' + File::SEPARATOR + 'examples'
10
+
11
+ require 'test_suite/model'
12
+ require 'optparse'
13
+ require 'ostruct'
14
+
15
+ def get_options(args)
16
+ options = OpenStruct.new
17
+
18
+ options.db = nil
19
+ options.auto = false
20
+ options.suite = nil
21
+ options.ident = nil
22
+ options.modules = []
23
+
24
+ opts = OptionParser.new do |opts|
25
+ opts.banner ="Usage: #{$0} [-p db_path] SUITE_IDENT TEST_IDENT MODULE [...]"
26
+ opts.separator 'Add Modules to a Test in database'
27
+ opts.separator 'Options:'
28
+
29
+ opts.on( '-p', '--db-path PATH', 'Path to TestSuite GitDS' ) do |path|
30
+ options.db = path
31
+ options.auto = true
32
+ end
33
+
34
+ opts.on_tail( '-?', '--help', 'Show this message') do
35
+ puts opts
36
+ exit -1
37
+ end
38
+ end
39
+
40
+ opts.parse!(args)
41
+
42
+ options.db = GitDS::Database.top_level if not options.db
43
+ raise "Invalid database" if not options.db
44
+
45
+ if args.count > 2
46
+ options.suite = args.shift
47
+ options.ident = args.shift
48
+ args.each { |m| options.modules << m }
49
+ else
50
+ puts opts.banner
51
+ exit -2
52
+ end
53
+
54
+ options
55
+ end
56
+
57
+ # ----------------------------------------------------------------------
58
+ if __FILE__ == $0
59
+ options = get_options(ARGV)
60
+
61
+ model = TestSuiteModel.new(GitDS::Database.connect(options.db, options.auto))
62
+ raise "Could not connect to Model!" if not model
63
+
64
+ s = model.test_suite(options.suite)
65
+ raise "Could not find TestSuite #{options.suite}" if not s
66
+
67
+ t = s.test(options.ident)
68
+ raise "Could not find Test #{options.ident}" if not t
69
+
70
+ options.modules.each do |ident|
71
+ m = model.module(ident)
72
+ raise "Module #{m} not found" if not m
73
+
74
+ t.add_module(m)
75
+ end
76
+
77
+ exit 0
78
+ end
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+ # Add a Test to a TestSuite database repo
3
+ # Copyright 2011 Thoughtgang <http://www.thoughtgang.org>
4
+
5
+ # Add examples dir and lib/git-ds to ruby path
6
+ BASE=File.dirname(File.expand_path(__FILE__)\
7
+ ).split(File::SEPARATOR)[0..-4].join(File::SEPARATOR)
8
+ $: << BASE + File::SEPARATOR + 'lib'
9
+ $: << BASE + File::SEPARATOR + 'doc' + File::SEPARATOR + 'examples'
10
+
11
+ require 'test_suite/model'
12
+ require 'optparse'
13
+ require 'ostruct'
14
+
15
+ def get_options(args)
16
+ options = OpenStruct.new
17
+
18
+ options.db = nil
19
+ options.auto = false
20
+ options.suite = nil
21
+ options.ident = nil
22
+ options.modules = []
23
+
24
+ opts = OptionParser.new do |opts|
25
+ opts.banner = "Usage: #{$0} [-p db_path] SUITE_IDENT TEST_IDENT [MODULE...]"
26
+ opts.separator 'Add a Test to Test Suite in database'
27
+ opts.separator 'Options:'
28
+
29
+ opts.on( '-p', '--db-path PATH', 'Path to TestSuite GitDS' ) do |path|
30
+ options.db = path
31
+ options.auto = true
32
+ end
33
+
34
+ opts.on_tail( '-?', '--help', 'Show this message') do
35
+ puts opts
36
+ exit -1
37
+ end
38
+ end
39
+
40
+ opts.parse!(args)
41
+
42
+ options.db = GitDS::Database.top_level if not options.db
43
+ raise "Invalid database" if not options.db
44
+
45
+ if args.count >= 2
46
+ options.suite = args.shift
47
+ options.ident = args.shift
48
+ args.each { |m| options.modules << m }
49
+ else
50
+ puts opts.banner
51
+ exit -2
52
+ end
53
+
54
+ options
55
+ end
56
+
57
+ # ----------------------------------------------------------------------
58
+ if __FILE__ == $0
59
+ options = get_options(ARGV)
60
+
61
+ model = TestSuiteModel.new(GitDS::Database.connect(options.db, options.auto))
62
+ raise "Could not connect to Model!" if not model
63
+
64
+ s = model.test_suite(options.suite)
65
+ raise "Could not find TestSuite #{options.suite}" if not s
66
+
67
+ mods = []
68
+ options.modules.each do |ident|
69
+ m = model.module(ident)
70
+ raise "Module #{m} not found" if not m
71
+ mods << m
72
+ end
73
+
74
+ s.add_test(options.ident, mods)
75
+
76
+ exit 0
77
+ end