dister 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class CoreTest < Test::Unit::TestCase
4
+ context "Using FakeFS -" do
5
+ setup do
6
+ FakeFS.activate!
7
+ end
8
+
9
+ teardown do
10
+ FakeFS.deactivate!
11
+ end
12
+
13
+ context "file uploading" do
14
+ should "not upload non-existing files" do
15
+ STDERR.stubs(:puts)
16
+ core = Dister::Core.new
17
+ assert !core.file_upload("foo")
18
+ end
19
+
20
+ should "upload an existing files" do
21
+ STDOUT.stubs(:puts)
22
+ FileUtils.touch "foo"
23
+ core = Dister::Core.new
24
+ core.stubs(:puts)
25
+ StudioApi::File.expects(:find).once.returns([])
26
+ StudioApi::File.expects(:upload).\
27
+ with(is_a(File), nil, {}).\
28
+ once.\
29
+ returns(true)
30
+ assert core.file_upload("foo", {})
31
+ end
32
+ end
33
+
34
+ context "While executing 'dister bundle' it" do
35
+ setup do
36
+ @core = Dister::Core.new
37
+ @core.stubs(:puts)
38
+ end
39
+
40
+ should 'package all required gems' do
41
+ File.expects(:exists?).returns(true)
42
+ @core.expects(:system).with("cd #{Dister::Core::APP_ROOT}").once.returns(true)
43
+ File.expects(:exists?).returns(true)
44
+ @core.expects(:system).with("rm -R vendor/cache").once.returns(true)
45
+ @core.expects(:system).with("bundle package").once.returns(true)
46
+ @core.package_gems
47
+ end
48
+
49
+ should "create a tarball of the application's source files" do
50
+ File.stubs(:exists?).returns(true)
51
+ @core.expects(:system).with("rm .dister/dister_application.tar.gz").once.returns(true)
52
+ @core.expects(:system).with("tar -czf .dister/dister_application.tar.gz ../dister/ --exclude=.dister &> /dev/null").once.returns(true)
53
+ @core.package_app
54
+ end
55
+ end
56
+
57
+ context "verify status" do
58
+ setup do
59
+ @core = Dister::Core.new
60
+ @core.stubs(:puts)
61
+ Dister::Utils.stubs(:print)
62
+ end
63
+
64
+ should "raise an error if something is wrong" do
65
+ STDOUT.stubs(:puts)
66
+ fake_status = mock()
67
+ fake_status.stubs(:state).returns("BOOM")
68
+ fake_status.stubs(:issues).returns("Bad mood")
69
+ fake_appliance = mock()
70
+ fake_appliance.stubs(:edit_url).returns("http://susestudio.com")
71
+ fake_appliance.stubs(:status).returns(fake_status)
72
+ @core.stubs(:appliance).returns(fake_appliance)
73
+ assert_raise SystemExit do
74
+ @core.verify_status
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,82 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class DbAdapterTest < Test::Unit::TestCase
4
+
5
+ GOOD_CONFIG = File.expand_path('../fixtures/supported_database.yml', __FILE__)
6
+ BAD_CONFIG = File.expand_path('../fixtures/unsupported_database.yml', __FILE__)
7
+
8
+
9
+ context "Initialization" do
10
+ should "raise an exception if the adapter doesn't exist" do
11
+ assert_raises RuntimeError do
12
+ adapter = Dister::DbAdapter.new BAD_CONFIG
13
+ end
14
+ end
15
+
16
+ should "not raise an exception if the adapter exists" do
17
+ assert_nothing_raised do
18
+ adapter = Dister::DbAdapter.new GOOD_CONFIG
19
+ end
20
+ end
21
+ end
22
+
23
+ context "dump handling" do
24
+ should "tell you there's no dump" do
25
+ adapter = Dister::DbAdapter.new GOOD_CONFIG
26
+ assert !adapter.has_dump?
27
+
28
+ # there's no foo.sql file
29
+ adapter = Dister::DbAdapter.new GOOD_CONFIG, "foo.sql"
30
+ assert !adapter.has_dump?
31
+ end
32
+
33
+ should "tell you there's a dump" do
34
+ begin
35
+ FileUtils.touch "foo.sql"
36
+ adapter = Dister::DbAdapter.new GOOD_CONFIG, "foo.sql"
37
+ assert adapter.has_dump?
38
+ ensure
39
+ FileUtils.rm_rf "foo.sql"
40
+ end
41
+ end
42
+ end
43
+
44
+ context "mysql adapter" do
45
+ setup do
46
+ @user = "foo"
47
+ @password = "secret"
48
+ @db_name = "cool_rails_app"
49
+ @adapter = "mysql"
50
+ @dump = "cool_rails_app.sql"
51
+ @db_adapter = Dister::DbAdapter.new GOOD_CONFIG, @dump
52
+ end
53
+
54
+ should "return package name" do
55
+ required_packages = @db_adapter.packages
56
+ assert required_packages.include?("mysql-community-server")
57
+ assert required_packages.include?("ruby-mysql")
58
+ end
59
+
60
+ should "return daemon name" do
61
+ assert_equal "mysql", @db_adapter.daemon_name
62
+ end
63
+
64
+ should "return create user command" do
65
+ assert_nothing_raised do
66
+ cmd = @db_adapter.create_user_cmd
67
+ assert cmd.include? @user
68
+ assert cmd.include? @password
69
+ end
70
+ end
71
+
72
+ should "restore dump" do
73
+ assert_nothing_raised do
74
+ cmd = @db_adapter.restore_dump_cmd
75
+ assert cmd.include? @user
76
+ assert cmd.include? @password
77
+ assert cmd.include? @db_name
78
+ assert cmd.include? @dump
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,17 @@
1
+ defaults: &defaults
2
+ adapter: mysql
3
+ host: 127.0.0.1
4
+ username: foo
5
+ password: secret
6
+
7
+ development:
8
+ <<: *defaults
9
+ database: cool_rails_app_dev
10
+
11
+ test: &test
12
+ <<: *defaults
13
+ database: cool_rails_app_test
14
+
15
+ production:
16
+ <<: *defaults
17
+ database: cool_rails_app
@@ -0,0 +1,231 @@
1
+ ---
2
+ 38:
3
+ name: SLED 10 SP3, KDE 3 desktop
4
+ basesystem: SLED10_SP3
5
+ appliance_id: "272626"
6
+ description: SLED 10 SP3, with KDE
7
+ 27:
8
+ name: SLES 11, Server
9
+ basesystem: SLES11
10
+ appliance_id: "202461"
11
+ description: SLES 11
12
+ 16:
13
+ name: openSUSE 11.2, Minimal X
14
+ basesystem: "11.2"
15
+ appliance_id: "123665"
16
+ description: Graphical system + IceWM
17
+ 5:
18
+ name: openSUSE 11.1, GNOME desktop
19
+ basesystem: "11.1"
20
+ appliance_id: "2162"
21
+ description: Base system + GNOME
22
+ 44:
23
+ name: SLES 11 SP1, VMware
24
+ basesystem: SLES11_SP1_VMware
25
+ appliance_id: "307097"
26
+ description: SLES 11 SP1, VMware branded
27
+ 33:
28
+ name: openSUSE 11.3, GNOME desktop
29
+ basesystem: "11.3"
30
+ appliance_id: "232521"
31
+ description: Base system + GNOME
32
+ 22:
33
+ name: SLED 11 SP1, GNOME desktop
34
+ basesystem: SLED11_SP1
35
+ appliance_id: "202446"
36
+ description: SLED 11 SP1, with GNOME
37
+ 11:
38
+ name: SLES 11, Server
39
+ basesystem: SLES11
40
+ appliance_id: "14775"
41
+ description: SLES 11
42
+ 0:
43
+ name: openSUSE 11.1, Just enough OS (JeOS)
44
+ basesystem: "11.1"
45
+ appliance_id: "3505"
46
+ description: Tiny, minimalistic appliances
47
+ 39:
48
+ name: SLED 10 SP3, GNOME desktop
49
+ basesystem: SLED10_SP3
50
+ appliance_id: "272627"
51
+ description: SLED 10 SP3, with GNOME
52
+ 28:
53
+ name: SLED 11 SP1, GNOME desktop
54
+ basesystem: SLED11_SP1
55
+ appliance_id: "202476"
56
+ description: SLED 11 SP1, with GNOME
57
+ 17:
58
+ name: openSUSE 11.2, KDE 4 desktop
59
+ basesystem: "11.2"
60
+ appliance_id: "123666"
61
+ description: Base system + KDE 4
62
+ 6:
63
+ name: SLED 10, KDE 3 desktop
64
+ basesystem: SLED10_SP2
65
+ appliance_id: "14769"
66
+ description: SLED 10, with KDE
67
+ 45:
68
+ name: SLES 11 SP1, VMware
69
+ basesystem: SLES11_SP1_VMware
70
+ appliance_id: "307126"
71
+ description: SLES 11 SP1, VMware branded
72
+ 34:
73
+ name: SLED 11, KDE 4 desktop
74
+ basesystem: SLED11
75
+ appliance_id: "255146"
76
+ description: SLED 11, with KDE 4
77
+ 23:
78
+ name: SLED 11, KDE 4 desktop
79
+ basesystem: SLED11
80
+ appliance_id: "202458"
81
+ description: SLED 11, with KDE 4
82
+ 12:
83
+ name: SLES 11, Just enough OS (JeOS)
84
+ basesystem: SLES11
85
+ appliance_id: "26667"
86
+ description: Minimal SLES
87
+ 1:
88
+ name: openSUSE 11.1, Server
89
+ basesystem: "11.1"
90
+ appliance_id: "2158"
91
+ description: A text-only base
92
+ 40:
93
+ name: SLES 10 SP2, Server
94
+ basesystem: SLES10_SP2
95
+ appliance_id: "272628"
96
+ description: SLES 10 SP2
97
+ 29:
98
+ name: openSUSE 11.3, Just enough OS (JeOS)
99
+ basesystem: "11.3"
100
+ appliance_id: "232516"
101
+ description: Tiny, minimalistic appliances
102
+ 18:
103
+ name: openSUSE 11.2, GNOME desktop
104
+ basesystem: "11.2"
105
+ appliance_id: "123667"
106
+ description: Base system + GNOME
107
+ 7:
108
+ name: SLED 10, GNOME desktop
109
+ basesystem: SLED10_SP2
110
+ appliance_id: "14770"
111
+ description: SLED 10, with GNOME
112
+ 35:
113
+ name: SLED 11, GNOME desktop
114
+ basesystem: SLED11
115
+ appliance_id: "255147"
116
+ description: SLED 11, with GNOME
117
+ 24:
118
+ name: SLED 11, GNOME desktop
119
+ basesystem: SLED11
120
+ appliance_id: "202459"
121
+ description: SLED 11, with GNOME
122
+ 13:
123
+ name: SLES 11, Just enough OS (JeOS)
124
+ basesystem: SLES11
125
+ appliance_id: "26694"
126
+ description: Minimal SLES
127
+ 2:
128
+ name: openSUSE 11.1, Minimal X
129
+ basesystem: "11.1"
130
+ appliance_id: "2159"
131
+ description: Graphical system + IceWM
132
+ 41:
133
+ name: SLES 10 SP3, Server
134
+ basesystem: SLES10_SP3
135
+ appliance_id: "272629"
136
+ description: SLES 10 SP3
137
+ 30:
138
+ name: openSUSE 11.3, Server
139
+ basesystem: "11.3"
140
+ appliance_id: "232517"
141
+ description: A text-only base
142
+ 19:
143
+ name: SLES 11 SP1, Just enough OS (JeOS)
144
+ basesystem: SLES11_SP1
145
+ appliance_id: "202443"
146
+ description: Minimal SLES 11 SP1
147
+ 8:
148
+ name: SLES 10, Server
149
+ basesystem: SLES10_SP2
150
+ appliance_id: "14771"
151
+ description: SLES 10
152
+ 36:
153
+ name: SLED 10 SP2, KDE 3 desktop
154
+ basesystem: SLED10_SP2
155
+ appliance_id: "272624"
156
+ description: SLED 10 SP2, with KDE
157
+ 25:
158
+ name: SLES 11, Just enough OS (JeOS)
159
+ basesystem: SLES11
160
+ appliance_id: "202460"
161
+ description: Minimal SLES
162
+ 14:
163
+ name: openSUSE 11.2, Just enough OS (JeOS)
164
+ basesystem: "11.2"
165
+ appliance_id: "123663"
166
+ description: Tiny, minimalistic appliances
167
+ 3:
168
+ name: openSUSE 11.1, KDE 3 desktop
169
+ basesystem: "11.1"
170
+ appliance_id: "2160"
171
+ description: Base system + KDE 3
172
+ 42:
173
+ name: SLES 11 SP1, VMware
174
+ basesystem: SLES11_SP1_VMware
175
+ appliance_id: "294108"
176
+ description: SLES 11 SP1, VMware branded
177
+ 31:
178
+ name: openSUSE 11.3, Minimal X
179
+ basesystem: "11.3"
180
+ appliance_id: "232518"
181
+ description: Graphical system + IceWM
182
+ 20:
183
+ name: SLES 11 SP1, Server
184
+ basesystem: SLES11_SP1
185
+ appliance_id: "202444"
186
+ description: SLES 11 SP1
187
+ 9:
188
+ name: SLED 11, KDE 4 desktop
189
+ basesystem: SLED11
190
+ appliance_id: "14772"
191
+ description: SLED 11, with KDE 4
192
+ 37:
193
+ name: SLED 10 SP2, GNOME desktop
194
+ basesystem: SLED10_SP2
195
+ appliance_id: "272625"
196
+ description: SLED 10 SP2, with GNOME
197
+ 26:
198
+ name: openSUSE 11.2, Minimal X
199
+ basesystem: "11.2"
200
+ appliance_id: "160586"
201
+ description: Graphical system + IceWM
202
+ 15:
203
+ name: openSUSE 11.2, Server
204
+ basesystem: "11.2"
205
+ appliance_id: "123664"
206
+ description: A text-only base
207
+ 4:
208
+ name: openSUSE 11.1, KDE 4 desktop
209
+ basesystem: "11.1"
210
+ appliance_id: "2161"
211
+ description: Base system + KDE 4
212
+ 43:
213
+ name: SLES 11 SP1, VMware
214
+ basesystem: SLES11_SP1_VMware
215
+ appliance_id: "295918"
216
+ description: SLES 11 SP1, VMware branded
217
+ 32:
218
+ name: openSUSE 11.3, KDE 4 desktop
219
+ basesystem: "11.3"
220
+ appliance_id: "232520"
221
+ description: Base system + KDE 4
222
+ 21:
223
+ name: SLED 11 SP1, KDE 4 desktop
224
+ basesystem: SLED11_SP1
225
+ appliance_id: "202445"
226
+ description: SLED 11 SP1, with KDE 4
227
+ 10:
228
+ name: SLED 11, GNOME desktop
229
+ basesystem: SLED11
230
+ appliance_id: "14773"
231
+ description: SLED 11, with GNOME
@@ -0,0 +1,17 @@
1
+ defaults: &defaults
2
+ adapter: unsupported_adapter
3
+ host: 127.0.0.1
4
+ username: foo
5
+ password: secret
6
+
7
+ development:
8
+ <<: *defaults
9
+ database: cool_rails_app_dev
10
+
11
+ test: &test
12
+ <<: *defaults
13
+ database: cool_rails_app_test
14
+
15
+ production:
16
+ <<: *defaults
17
+ database: cool_rails_app
@@ -0,0 +1,128 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class OptionsTest < Test::Unit::TestCase
4
+
5
+ # Small helper method to use FakeFS for storing options.
6
+ def save_options(options_map, options_type)
7
+ options_path = case options_type
8
+ when :local then Dister::Options::LOCAL_PATH
9
+ when :global then Dister::Options::GLOBAL_PATH
10
+ else
11
+ raise "Invalid options type '#{options_type}'."
12
+ end
13
+ FileUtils.mkdir_p(File.dirname(options_path))
14
+ File.open(options_path, 'w') do |out|
15
+ YAML.dump(options_map, out)
16
+ end
17
+ end
18
+
19
+ context 'While initializing options it' do
20
+ setup do
21
+ FakeFS.activate!
22
+ end
23
+
24
+ teardown do
25
+ FakeFS.deactivate!
26
+ end
27
+
28
+ should 'read global and local options' do
29
+ global_options = {'username' => 'foo'}
30
+ save_options(global_options, :global)
31
+ local_options = {'appliance_id' => '1'}
32
+ save_options(local_options, :local)
33
+ assert_equal 'foo', Dister::Options.new.username
34
+ assert_equal '1', Dister::Options.new.appliance_id
35
+ end
36
+
37
+ should 'ensure the existence of a global and a local config file' do
38
+ Dister::Options.new
39
+ assert File.exists? Dister::Options::GLOBAL_PATH
40
+ assert File.exists? Dister::Options::LOCAL_PATH
41
+ end
42
+
43
+ should "provide a default global value for api_key" do
44
+ FileUtils.rm_rf Dister::Options::GLOBAL_PATH
45
+ FileUtils.rm_rf Dister::Options::LOCAL_PATH
46
+
47
+ options = Dister::Options.new
48
+
49
+ assert File.exists? Dister::Options::GLOBAL_PATH
50
+ assert File.exists? Dister::Options::LOCAL_PATH
51
+ assert_equal(Dister::Options::SUSE_STUDIO_DOT_COM_API_PATH,
52
+ options.api_path)
53
+ end
54
+ end
55
+
56
+ context 'For existing options it' do
57
+ setup do
58
+ FakeFS.activate!
59
+ @global = {'username' => 'foo', 'api_key' => 'bar'}
60
+ @local = {'appliance_id' => '0'}
61
+ save_options(@global, :global)
62
+ save_options(@local, :local)
63
+ @dister_options = Dister::Options.new
64
+ end
65
+
66
+ teardown do
67
+ FakeFS.deactivate!
68
+ end
69
+
70
+ should 'allow to store global and local options' do
71
+ assert @dister_options.appliance_id = '1'
72
+ assert_equal '1', @dister_options.appliance_id
73
+ assert @dister_options.username = 'bar'
74
+ assert_equal 'bar', @dister_options.username
75
+ end
76
+ end
77
+
78
+ context "Options entries are mapped to class methods" do
79
+ setup do
80
+ FakeFS.activate!
81
+ @global = {'username' => 'foo', 'api_key' => 'bar'}
82
+ @local = {'appliance_id' => '0'}
83
+ save_options(@global, :global)
84
+ save_options(@local, :local)
85
+ @dister_options = Dister::Options.new
86
+ end
87
+
88
+ teardown do
89
+ FakeFS.deactivate!
90
+ end
91
+
92
+ should "read existing options" do
93
+ [@global, @local].each do |options_map|
94
+ options_map.each do |key, value|
95
+ assert_nothing_raised do
96
+ assert_equal value, @dister_options.send(key)
97
+ end
98
+ end
99
+ end
100
+
101
+ assert_equal "foo", @dister_options.username
102
+ end
103
+
104
+ should "handle non existing options" do
105
+ assert_nothing_raised do
106
+ assert_equal nil, @dister_options.a_new_option
107
+ end
108
+ end
109
+
110
+ context "assignment operator" do
111
+ should "update existing options" do
112
+ [@global, @local].each do |options_map|
113
+ options_map.each do |key, value|
114
+ assert_nothing_raised do
115
+ @dister_options.send("#{key}=","#{value} NEW")
116
+ assert_equal "#{value} NEW", @dister_options.send(key)
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ should "create a new entry if it doesn't exist" do
123
+ @dister_options.a_new_option = "NEWBIE!"
124
+ assert_equal "NEWBIE!", @dister_options.a_new_option
125
+ end
126
+ end
127
+ end
128
+ end