knife-digital_ocean 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +112 -20
  4. data/Rakefile +6 -0
  5. data/knife-digital_ocean.gemspec +4 -0
  6. data/lib/chef/knife/digital_ocean_base.rb +15 -0
  7. data/lib/chef/knife/digital_ocean_domain_create.rb +9 -10
  8. data/lib/chef/knife/digital_ocean_domain_destroy.rb +5 -5
  9. data/lib/chef/knife/digital_ocean_domain_list.rb +1 -2
  10. data/lib/chef/knife/digital_ocean_domain_record_create.rb +18 -18
  11. data/lib/chef/knife/digital_ocean_domain_record_destroy.rb +9 -10
  12. data/lib/chef/knife/digital_ocean_domain_record_edit.rb +21 -21
  13. data/lib/chef/knife/digital_ocean_domain_record_list.rb +4 -5
  14. data/lib/chef/knife/digital_ocean_droplet_create.rb +4 -5
  15. data/lib/chef/knife/digital_ocean_droplet_destroy.rb +3 -6
  16. data/lib/chef/knife/digital_ocean_droplet_power.rb +66 -0
  17. data/lib/chef/knife/digital_ocean_droplet_powercycle.rb +48 -0
  18. data/lib/chef/knife/digital_ocean_droplet_reboot.rb +48 -0
  19. data/lib/chef/knife/digital_ocean_droplet_rebuild.rb +58 -0
  20. data/lib/chef/knife/digital_ocean_droplet_rename.rb +58 -0
  21. data/lib/chef/knife/digital_ocean_droplet_resize.rb +58 -0
  22. data/lib/chef/knife/digital_ocean_droplet_snapshot.rb +58 -0
  23. data/lib/chef/knife/digital_ocean_image_destroy.rb +42 -0
  24. data/lib/chef/knife/digital_ocean_image_list.rb +1 -1
  25. data/lib/chef/knife/digital_ocean_image_transfer.rb +66 -0
  26. data/lib/chef/knife/digital_ocean_region_list.rb +1 -1
  27. data/lib/chef/knife/digital_ocean_sshkey_create.rb +11 -11
  28. data/lib/chef/knife/digital_ocean_sshkey_destroy.rb +6 -6
  29. data/lib/chef/knife/digital_ocean_sshkey_list.rb +1 -1
  30. data/lib/knife-digital_ocean/version.rb +1 -1
  31. data/spec/fixtures/keys/id_rsa.pub +1 -0
  32. data/spec/fixtures/vcr_cassettes/accountinfo.yml +7 -9
  33. data/spec/fixtures/vcr_cassettes/domain_create.yml +65 -0
  34. data/spec/fixtures/vcr_cassettes/{domainlist.yml → domain_list.yml} +15 -12
  35. data/spec/fixtures/vcr_cassettes/domain_record_create.yml +65 -0
  36. data/spec/fixtures/vcr_cassettes/domain_record_list.yml +63 -0
  37. data/spec/fixtures/vcr_cassettes/droplet.yml +12 -17
  38. data/spec/fixtures/vcr_cassettes/droplet_power.yml +65 -0
  39. data/spec/fixtures/vcr_cassettes/droplet_powercycle.yml +127 -0
  40. data/spec/fixtures/vcr_cassettes/droplet_reboot.yml +127 -0
  41. data/spec/fixtures/vcr_cassettes/droplet_rebuild.yml +65 -0
  42. data/spec/fixtures/vcr_cassettes/droplet_rename.yml +127 -0
  43. data/spec/fixtures/vcr_cassettes/droplet_resize.yml +65 -0
  44. data/spec/fixtures/vcr_cassettes/droplet_snapshot.yml +1057 -0
  45. data/spec/fixtures/vcr_cassettes/image.yml +55 -59
  46. data/spec/fixtures/vcr_cassettes/public_images.yml +54 -59
  47. data/spec/fixtures/vcr_cassettes/region.yml +8 -10
  48. data/spec/fixtures/vcr_cassettes/sizes.yml +8 -10
  49. data/spec/fixtures/vcr_cassettes/sshkey.yml +8 -10
  50. data/spec/fixtures/vcr_cassettes/sshkey_create.yml +68 -0
  51. data/spec/lib/chef/knife/digital_ocean_account_info_spec.rb +4 -4
  52. data/spec/lib/chef/knife/digital_ocean_domain_create_spec.rb +35 -1
  53. data/spec/lib/chef/knife/digital_ocean_domain_list_spec.rb +8 -9
  54. data/spec/lib/chef/knife/digital_ocean_domain_record_create_spec.rb +37 -1
  55. data/spec/lib/chef/knife/digital_ocean_domain_record_list_spec.rb +34 -1
  56. data/spec/lib/chef/knife/digital_ocean_droplet_create_spec.rb +5 -1
  57. data/spec/lib/chef/knife/digital_ocean_droplet_list_spec.rb +4 -4
  58. data/spec/lib/chef/knife/digital_ocean_droplet_power_spec.rb +39 -0
  59. data/spec/lib/chef/knife/digital_ocean_droplet_powercycle_spec.rb +38 -0
  60. data/spec/lib/chef/knife/digital_ocean_droplet_reboot_spec.rb +38 -0
  61. data/spec/lib/chef/knife/digital_ocean_droplet_rebuild_spec.rb +39 -0
  62. data/spec/lib/chef/knife/digital_ocean_droplet_rename_spec.rb +39 -0
  63. data/spec/lib/chef/knife/digital_ocean_droplet_resize_spec.rb +39 -0
  64. data/spec/lib/chef/knife/digital_ocean_droplet_snapshot_spec.rb +39 -0
  65. data/spec/lib/chef/knife/digital_ocean_image_list_spec.rb +8 -10
  66. data/spec/lib/chef/knife/digital_ocean_region_list_spec.rb +4 -4
  67. data/spec/lib/chef/knife/digital_ocean_size_list_spec.rb +4 -4
  68. data/spec/lib/chef/knife/digital_ocean_sshkey_create_spec.rb +35 -1
  69. data/spec/lib/chef/knife/digital_ocean_sshkey_list_spec.rb +4 -4
  70. data/spec/spec_helper.rb +29 -2
  71. metadata +93 -6
  72. data/spec/lib/chef/knife/digital_ocean_domain_record_edit_spec.rb +0 -5
@@ -0,0 +1,68 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.digitalocean.com/v2/account/keys
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"name":"test-key","public_key":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDb2qoPVE2V/w5QZPC6MdPnnJVg8o9w4DNk7hT2rGAM7cyIOL4tqmmcfABPGCEpxen048aXhabpq2BgQXWP9WJw8/FUiqjV1Aohqyev5nl0v00f9xlFRfCP/hatNsn8EvnUL32ijJI/vnKaVhXF6cPz9mYH8DumKE9SxAXC9m6ALu/JJHPUmRqONTUwIASkdxiuBJsjIKei4jU0H1nb8dc/ar1f5KXGgnMTikMnoDIuZosv8+I8r1R2gTIx1HmdJaK9IJx3KbaEHoCasTAK5W2PiP/vkGKQlAjolakE6CVapgDOvkKH7YfT0UBB9JGsGMhEzUphZ6kddSBYLscpKhAx
9
+ gregf@betsy\n"}'
10
+ headers:
11
+ Content-Type:
12
+ - application/json
13
+ Authorization:
14
+ - Bearer FAKE_ACCESS_TOKEN
15
+ User-Agent:
16
+ - Faraday v0.9.0
17
+ Accept-Encoding:
18
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
19
+ Accept:
20
+ - "*/*"
21
+ response:
22
+ status:
23
+ code: 201
24
+ message: Created
25
+ headers:
26
+ Server:
27
+ - cloudflare-nginx
28
+ Date:
29
+ - Sun, 16 Nov 2014 03:56:19 GMT
30
+ Content-Type:
31
+ - application/json; charset=utf-8
32
+ Transfer-Encoding:
33
+ - chunked
34
+ Connection:
35
+ - keep-alive
36
+ Set-Cookie: _COOKIE_ID_
37
+ Status:
38
+ - 201 Created
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ Ratelimit-Limit:
46
+ - '1200'
47
+ Ratelimit-Remaining:
48
+ - '1167'
49
+ Ratelimit-Reset:
50
+ - '1416110320'
51
+ Etag:
52
+ - '"e52cb08c8d62b177f6eb9d0533248fb4"'
53
+ Cache-Control:
54
+ - max-age=0, private, must-revalidate
55
+ X-Request-Id:
56
+ - 6d5b9288-40a9-4560-a3f9-99c6a4d7f748
57
+ X-Runtime:
58
+ - '0.066654'
59
+ Cf-Ray:
60
+ - 18a0c20d093d0ec7-EWR
61
+ body:
62
+ encoding: UTF-8
63
+ string: '{"ssh_key":{"id":513586,"fingerprint":"42:98:44:fc:b9:91:ae:92:8f:5c:e4:1a:1c:92:cb:94","public_key":"ssh-rsa
64
+ AAAAB3NzaC1yc2EAAAADAQABAAABAQDb2qoPVE2V/w5QZPC6MdPnnJVg8o9w4DNk7hT2rGAM7cyIOL4tqmmcfABPGCEpxen048aXhabpq2BgQXWP9WJw8/FUiqjV1Aohqyev5nl0v00f9xlFRfCP/hatNsn8EvnUL32ijJI/vnKaVhXF6cPz9mYH8DumKE9SxAXC9m6ALu/JJHPUmRqONTUwIASkdxiuBJsjIKei4jU0H1nb8dc/ar1f5KXGgnMTikMnoDIuZosv8+I8r1R2gTIx1HmdJaK9IJx3KbaEHoCasTAK5W2PiP/vkGKQlAjolakE6CVapgDOvkKH7YfT0UBB9JGsGMhEzUphZ6kddSBYLscpKhAx
65
+ gregf@betsy","name":"test-key"}}'
66
+ http_version:
67
+ recorded_at: Sun, 16 Nov 2014 03:56:19 GMT
68
+ recorded_with: VCR 2.9.3
@@ -12,22 +12,22 @@ describe Chef::Knife::DigitalOceanAccountInfo do
12
12
  allow(subject).to receive(:puts)
13
13
  end
14
14
 
15
- describe "#run" do
16
- it "should validate the Digital Ocean config keys exist" do
15
+ describe '#run' do
16
+ it 'should validate the Digital Ocean config keys exist' do
17
17
  VCR.use_cassette('accountinfo') do
18
18
  expect(subject).to receive(:validate!)
19
19
  subject.run
20
20
  end
21
21
  end
22
22
 
23
- it "should output the column headers" do
23
+ it 'should output the column headers' do
24
24
  VCR.use_cassette('accountinfo') do
25
25
  expect(subject).to receive(:puts).with(/^UUID\s+Email\s+Droplet Limit\s+Email Verified\n/)
26
26
  subject.run
27
27
  end
28
28
  end
29
29
 
30
- it "should output a list of the available Digital Ocean account info" do
30
+ it 'should output a list of the available Digital Ocean account info' do
31
31
  VCR.use_cassette('accountinfo') do
32
32
  expect(subject).to receive(:puts).with(/\b49e2e737d3a7407a042bb7e88f4da8629166f2b9\s+greg@gregf.org\s+20\s+true\s+\n/)
33
33
  subject.run
@@ -1,5 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chef::Knife::DigitalOceanDomainCreate do
4
- pending
4
+
5
+ subject { Chef::Knife::DigitalOceanDomainCreate.new }
6
+
7
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
+
9
+ before :each do
10
+ Chef::Knife::DigitalOceanDomainCreate.load_deps
11
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
+ allow(subject).to receive(:puts)
13
+ subject.config[:name] = 'kitchen-digital.org'
14
+ subject.config[:ip_address] = '192.168.1.1'
15
+ end
16
+
17
+ describe '#run' do
18
+ it 'should validate the Digital Ocean config keys exist' do
19
+ VCR.use_cassette('domain_create') do
20
+ expect(subject).to receive(:validate!)
21
+ subject.run
22
+ end
23
+ end
24
+
25
+ it 'should create the domain and exit with 0' do
26
+ VCR.use_cassette('domain_create') do
27
+ allow(subject.client).to receive_message_chain(:domains, :create)
28
+ expect { subject.run }.not_to raise_error
29
+ end
30
+ end
31
+
32
+ it 'should return OK' do
33
+ VCR.use_cassette('domain_create') do
34
+ expect($stdout).to receive(:puts).with('OK')
35
+ expect(subject.run).to eq nil
36
+ end
37
+ end
38
+ end
5
39
  end
@@ -7,29 +7,28 @@ describe Chef::Knife::DigitalOceanDomainList do
7
7
  let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
8
 
9
9
  before :each do
10
- Chef::Knife::DigitalOceanImageList.load_deps
10
+ Chef::Knife::DigitalOceanDomainList.load_deps
11
11
  Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
- Chef::Config['knife']['public_images'] = true
13
12
  allow(subject).to receive(:puts)
14
13
  end
15
14
 
16
- describe "#run" do
17
- it "should validate the Digital Ocean config keys exist" do
18
- VCR.use_cassette('domainlist') do
15
+ describe '#run' do
16
+ it 'should validate the Digital Ocean config keys exist' do
17
+ VCR.use_cassette('domain_list') do
19
18
  expect(subject).to receive(:validate!)
20
19
  subject.run
21
20
  end
22
21
  end
23
22
 
24
- it "should output the column headers" do
25
- VCR.use_cassette('domainlist') do
23
+ it 'should output the column headers' do
24
+ VCR.use_cassette('domain_list') do
26
25
  expect(subject).to receive(:puts).with(/^Name\s+TTL/)
27
26
  subject.run
28
27
  end
29
28
  end
30
29
 
31
- it "should output a list of the available Digital Ocean domains" do
32
- VCR.use_cassette('domainlist') do
30
+ it 'should output a list of the available Digital Ocean domains' do
31
+ VCR.use_cassette('domain_list') do
33
32
  expect(subject).to receive(:puts).with(/\bgregf.org\s+1800\n/)
34
33
  subject.run
35
34
  end
@@ -1,5 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chef::Knife::DigitalOceanDomainRecordCreate do
4
- pending
4
+
5
+ subject { Chef::Knife::DigitalOceanDomainRecordCreate.new }
6
+
7
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
+
9
+ before :each do
10
+ Chef::Knife::DigitalOceanDomainRecordCreate.load_deps
11
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
+ allow(subject).to receive(:puts)
13
+ subject.config[:domain] = 'kitchen-digital.org'
14
+ subject.config[:type] = 'A'
15
+ subject.config[:name] = 'www'
16
+ subject.config[:data] = '192.168.1.1'
17
+ end
18
+
19
+ describe '#run' do
20
+ it 'should validate the Digital Ocean config keys exist' do
21
+ VCR.use_cassette('domain_record_create') do
22
+ expect(subject).to receive(:validate!)
23
+ subject.run
24
+ end
25
+ end
26
+
27
+ it 'should create the domain record and exit with 0' do
28
+ VCR.use_cassette('domain_record_create') do
29
+ allow(subject.client).to receive_message_chain(:domain_records, :create)
30
+ expect { subject.run }.not_to raise_error
31
+ end
32
+ end
33
+
34
+ it 'should return OK' do
35
+ VCR.use_cassette('domain_record_create') do
36
+ expect($stdout).to receive(:puts).with('OK')
37
+ expect(subject.run).to eq nil
38
+ end
39
+ end
40
+ end
5
41
  end
@@ -1,5 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chef::Knife::DigitalOceanDomainRecordList do
4
- pending
4
+
5
+ subject { Chef::Knife::DigitalOceanDomainRecordList.new }
6
+
7
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
+
9
+ before :each do
10
+ Chef::Knife::DigitalOceanDomainRecordList.load_deps
11
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
+ allow(subject).to receive(:puts)
13
+ subject.config[:name] = 'kitchen-digital.org'
14
+ end
15
+
16
+ describe '#run' do
17
+ it 'should validate the Digital Ocean config keys exist' do
18
+ VCR.use_cassette('domain_record_list') do
19
+ expect(subject).to receive(:validate!)
20
+ subject.run
21
+ end
22
+ end
23
+
24
+ it 'should output the column headers' do
25
+ VCR.use_cassette('domain_record_list') do
26
+ expect(subject).to receive(:puts).with(/^ID\s+Type\s+Name\s+Data/)
27
+ subject.run
28
+ end
29
+ end
30
+
31
+ it 'should output a list of the available Digital Ocean domains' do
32
+ VCR.use_cassette('domain_record_list') do
33
+ expect(subject).to receive(:puts).with(/\b3364507\s+A\s+www\s+192.168.1.1\s+\n/)
34
+ subject.run
35
+ end
36
+ end
37
+ end
5
38
  end
@@ -55,7 +55,8 @@ describe Chef::Knife::DigitalOceanDropletCreate do
55
55
  context 'bootstrapping for chef-server' do
56
56
  let(:custom_config) do
57
57
  {
58
- bootstrap: true
58
+ bootstrap: true,
59
+ id: 123
59
60
  }
60
61
  end
61
62
 
@@ -63,6 +64,7 @@ describe Chef::Knife::DigitalOceanDropletCreate do
63
64
  let(:subject) do
64
65
  s = super()
65
66
  allow(s.client).to receive_message_chain(:droplets, :create).and_return mock_api_response(api_response)
67
+ allow(s.client).to receive_message_chain(:droplets, :find, :status).and_return 'new'
66
68
  allow(s).to receive(:ip_address_available).and_return '123.123.123.123'
67
69
  allow(s).to receive(:tcp_test_ssh).and_return true
68
70
  s
@@ -96,6 +98,7 @@ describe Chef::Knife::DigitalOceanDropletCreate do
96
98
  let(:subject) do
97
99
  s = super()
98
100
  allow(s.client).to receive_message_chain(:droplets, :create).and_return mock_api_response(api_response)
101
+ allow(s.client).to receive_message_chain(:droplets, :find, :status).and_return 'new'
99
102
  allow(s).to receive(:ip_address_available).and_return '123.123.123.123'
100
103
  allow(s).to receive(:tcp_test_ssh).and_return true
101
104
  s
@@ -135,6 +138,7 @@ describe Chef::Knife::DigitalOceanDropletCreate do
135
138
  let(:subject) do
136
139
  s = super()
137
140
  allow(s.client).to receive_message_chain(:droplets, :create).and_return mock_api_response(api_response)
141
+ allow(s.client).to receive_message_chain(:droplets, :find, :status).and_return 'new'
138
142
  allow(s).to receive(:ip_address_available).and_return '123.123.123.123'
139
143
  allow(s).to receive(:tcp_test_ssh).and_return true
140
144
  s
@@ -13,22 +13,22 @@ describe Chef::Knife::DigitalOceanDropletList do
13
13
  allow(subject).to receive(:puts)
14
14
  end
15
15
 
16
- describe "#run" do
17
- it "should validate the Digital Ocean config keys exist" do
16
+ describe '#run' do
17
+ it 'should validate the Digital Ocean config keys exist' do
18
18
  VCR.use_cassette('droplet') do
19
19
  expect(subject).to receive(:validate!)
20
20
  subject.run
21
21
  end
22
22
  end
23
23
 
24
- it "should output the column headers" do
24
+ it 'should output the column headers' do
25
25
  VCR.use_cassette('droplet') do
26
26
  expect(subject).to receive(:puts).with(/^ID\s+Name\s+Size\s+Region\s+IPv4\s+Image\s+Status\n/)
27
27
  subject.run
28
28
  end
29
29
  end
30
30
 
31
- it "should output a list of the available Digital Ocean Droplets" do
31
+ it 'should output a list of the available Digital Ocean Droplets' do
32
32
  VCR.use_cassette('droplet') do
33
33
  expect(subject).to receive(:puts).with(/\b2257086\b/)
34
34
  subject.run
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Knife::DigitalOceanDropletPower do
4
+
5
+ subject { Chef::Knife::DigitalOceanDropletPower.new }
6
+
7
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
+
9
+ before :each do
10
+ Chef::Knife::DigitalOceanDropletPower.load_deps
11
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
+ allow(subject).to receive(:puts)
13
+ allow(subject).to receive(:wait_for_status).and_return('OK')
14
+ subject.config[:id] = '3195306'
15
+ subject.config[:action] = 'off'
16
+ end
17
+
18
+ describe '#run' do
19
+ it 'should validate the Digital Ocean config keys exist' do
20
+ VCR.use_cassette('droplet_power') do
21
+ expect(subject).to receive(:validate!)
22
+ subject.run
23
+ end
24
+ end
25
+
26
+ it 'should power the droplet and exit with 0' do
27
+ VCR.use_cassette('droplet_power') do
28
+ allow(subject.client).to receive_message_chain(:droplet_actions, :power)
29
+ expect { subject.run }.not_to raise_error
30
+ end
31
+ end
32
+
33
+ it 'should return OK' do
34
+ VCR.use_cassette('droplet_power') do
35
+ expect(subject.run).to eq 'OK'
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Knife::DigitalOceanDropletPowercycle do
4
+
5
+ subject { Chef::Knife::DigitalOceanDropletPowercycle.new }
6
+
7
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
+
9
+ before :each do
10
+ Chef::Knife::DigitalOceanDropletPowercycle.load_deps
11
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
+ allow(subject).to receive(:puts)
13
+ allow(subject).to receive(:wait_for_status).and_return('OK')
14
+ subject.config[:id] = '3193966'
15
+ end
16
+
17
+ describe '#run' do
18
+ it 'should validate the Digital Ocean config keys exist' do
19
+ VCR.use_cassette('droplet_powercycle') do
20
+ expect(subject).to receive(:validate!)
21
+ subject.run
22
+ end
23
+ end
24
+
25
+ it 'should powercycle the droplet and exit with 0' do
26
+ VCR.use_cassette('droplet_powercycle') do
27
+ allow(subject.client).to receive_message_chain(:droplet_actions, :power_cycle)
28
+ expect { subject.run }.not_to raise_error
29
+ end
30
+ end
31
+
32
+ it 'should return OK' do
33
+ VCR.use_cassette('droplet_powercycle') do
34
+ expect(subject.run).to eq 'OK'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Knife::DigitalOceanDropletReboot do
4
+
5
+ subject { Chef::Knife::DigitalOceanDropletReboot.new }
6
+
7
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
+
9
+ before :each do
10
+ Chef::Knife::DigitalOceanDropletReboot.load_deps
11
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
+ allow(subject).to receive(:puts)
13
+ allow(subject).to receive(:wait_for_status).and_return('OK')
14
+ subject.config[:id] = '3193966'
15
+ end
16
+
17
+ describe '#run' do
18
+ it 'should validate the Digital Ocean config keys exist' do
19
+ VCR.use_cassette('droplet_reboot') do
20
+ expect(subject).to receive(:validate!)
21
+ subject.run
22
+ end
23
+ end
24
+
25
+ it 'should reboot the droplet and exit with 0' do
26
+ VCR.use_cassette('droplet_reboot') do
27
+ allow(subject.client).to receive_message_chain(:droplet_actions, :reboot)
28
+ expect { subject.run }.not_to raise_error
29
+ end
30
+ end
31
+
32
+ it 'should return OK' do
33
+ VCR.use_cassette('droplet_reboot') do
34
+ expect(subject.run).to eq 'OK'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Knife::DigitalOceanDropletRebuild do
4
+
5
+ subject { Chef::Knife::DigitalOceanDropletRebuild.new }
6
+
7
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
8
+
9
+ before :each do
10
+ Chef::Knife::DigitalOceanDropletRebuild.load_deps
11
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
12
+ allow(subject).to receive(:puts)
13
+ allow(subject).to receive(:wait_for_status).and_return('OK')
14
+ subject.config[:id] = '3193966'
15
+ subject.config[:image] = '8073571'
16
+ end
17
+
18
+ describe '#run' do
19
+ it 'should validate the Digital Ocean config keys exist' do
20
+ VCR.use_cassette('droplet_rebuild') do
21
+ expect(subject).to receive(:validate!)
22
+ subject.run
23
+ end
24
+ end
25
+
26
+ it 'should rebuild the droplet and exit with 0' do
27
+ VCR.use_cassette('droplet_rebuild') do
28
+ allow(subject.client).to receive_message_chain(:droplet_actions, :rebuild)
29
+ expect { subject.run }.not_to raise_error
30
+ end
31
+ end
32
+
33
+ it 'should return OK' do
34
+ VCR.use_cassette('droplet_rebuild') do
35
+ expect(subject.run).to eq 'OK'
36
+ end
37
+ end
38
+ end
39
+ end