datadog_backup 1.0.0.alpha.1 → 1.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5db8a5e804f30996a50247c24352e3fc1075971d141e37a2093987c510e9c9f1
4
- data.tar.gz: 41c6f43d1c15c7e789aabe5a5b9bd34d45e5f5712d4ada557fb32edaeac4dd11
3
+ metadata.gz: 04e0cf7686b2efa66728d2bb5d3fd021847368a6522b3b3ba3cc9012a118e32f
4
+ data.tar.gz: 22643d6160be735c52f6bc25c134f250adae2ce9b6751c62ee04265d2082b9d3
5
5
  SHA512:
6
- metadata.gz: f34c936e1a48773a4e0d600cfb23414c07b7197d7e72f9e1f7c3e1efd27c6b25b2ec9ab8643228b6b6d055f1b9c83762cf62e743418708ca8a02046405f256f7
7
- data.tar.gz: e3f2a91bf80a2ea6c265766b55e07b01ac885a002a4be41f3f6dc7dc9574bdd394a158c1258887814b387290915f9843dc5a07759dc74d5c9d5c491c155b4ffe
6
+ metadata.gz: 2293472fd1e18a59755e9e44ed1a39a17eb071e36de772c8ae146070138574f0726b016e9d0049cb8c8b8d625ce440a227ad5cf18a07a82ab77601580b96d01a
7
+ data.tar.gz: 583ff00c4a38005736f1bca85d80fc82eb6fbf8deb107044423ea2e7c3f87e05d82834f0051bf5fb7e5c2e476ea8c810292f93c392a3a1fe4e08a2be4327849e
@@ -0,0 +1 @@
1
+ require: rubocop-rspec
@@ -1,3 +1,16 @@
1
+ # [1.0.0-alpha.2](https://github.com/scribd/datadog_backup/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2021-01-19)
2
+
3
+
4
+ ### Features
5
+
6
+ * If resource doesn't exist in Datadog, the resource is recreated. ([f2f9e1f](https://github.com/scribd/datadog_backup/commit/f2f9e1f7b244eb3eeaaf121025769f9f327f4e1e))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * `datadog-backup` used to exit with an error if a resource
12
+ wasn't found in Datadog.
13
+
1
14
  # [1.0.0-alpha.1](https://github.com/scribd/datadog_backup/compare/v0.11.0...v1.0.0-alpha.1) (2021-01-17)
2
15
 
3
16
 
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ group :development, :test do
9
9
  gem 'guard-rspec'
10
10
  gem 'rspec'
11
11
  gem 'rubocop'
12
+ gem 'rubocop-rspec'
12
13
  end
@@ -55,8 +55,10 @@ def prereqs
55
55
  opts.on('--dashboards-only') do
56
56
  @options[:resources] = [DatadogBackup::Dashboards]
57
57
  end
58
- opts.on('--json',
59
- 'format backups as JSON instead of YAML. Does not impact `diffs` nor `restore`, but do not mix formats in the same backup-dir.') do
58
+ opts.on(
59
+ '--json',
60
+ 'format backups as JSON instead of YAML. Does not impact `diffs` nor `restore`, but do not mix formats in the same backup-dir.'
61
+ ) do
60
62
  @options[:output_format] = :json
61
63
  end
62
64
  opts.on('--no-color', 'removes colored output from diff format') do
@@ -99,8 +99,8 @@ module DatadogBackup
99
99
  if e.message.include?('Request failed with error ["404"')
100
100
  new_id = create(body).fetch('id')
101
101
 
102
- get_and_write_file(new_id)
103
102
  FileUtils.rm(find_file_by_id(id))
103
+ get_and_write_file(new_id)
104
104
  else
105
105
  raise e.message
106
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatadogBackup
4
- VERSION = '1.0.0.alpha.1'
4
+ VERSION = '1.0.0.alpha.2'
5
5
  end
@@ -19,10 +19,10 @@ describe DatadogBackup::Cli do
19
19
  resources: [DatadogBackup::Dashboards]
20
20
  }
21
21
  end
22
- let(:cli) { DatadogBackup::Cli.new(options) }
22
+ let(:cli) { described_class.new(options) }
23
23
  let(:dashboards) { DatadogBackup::Dashboards.new(options) }
24
24
 
25
- before(:example) do
25
+ before do
26
26
  allow(cli).to receive(:resource_instances).and_return([dashboards])
27
27
  end
28
28
 
@@ -39,18 +39,28 @@ describe DatadogBackup::Cli do
39
39
  }
40
40
  ]
41
41
  end
42
- before(:example) do
42
+
43
+ before do
43
44
  dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/stillthere.json")
44
45
  dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/alsostillthere.json")
45
46
  dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/deleted.json")
46
47
 
47
48
  allow(client_double).to receive(:instance_variable_get).with(:@dashboard_service).and_return(api_service_double)
48
- allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/dashboard', nil, nil,
49
+ allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
50
+ '/api/v1/dashboard',
51
+ nil,
52
+ nil,
49
53
  false).and_return(all_boards)
50
- allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/dashboard/stillthere', nil, nil,
54
+ allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
55
+ '/api/v1/dashboard/stillthere',
56
+ nil,
57
+ nil,
58
+ false).and_return(['200', {}])
59
+ allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
60
+ '/api/v1/dashboard/alsostillthere',
61
+ nil,
62
+ nil,
51
63
  false).and_return(['200', {}])
52
- allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/dashboard/alsostillthere', nil,
53
- nil, false).and_return(['200', {}])
54
64
  end
55
65
 
56
66
  it 'deletes the file locally as well' do
@@ -61,16 +71,18 @@ describe DatadogBackup::Cli do
61
71
  end
62
72
 
63
73
  describe '#diffs' do
64
- before(:example) do
74
+ subject { cli.diffs }
75
+
76
+ before do
65
77
  dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs1.json")
66
78
  dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs2.json")
67
79
  dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs3.json")
68
80
  allow(dashboards).to receive(:get_by_id).and_return({ 'text' => 'diff2' })
69
81
  allow(cli).to receive(:initialize_client).and_return(client_double)
70
82
  end
71
- subject { cli.diffs }
83
+
72
84
  it {
73
- is_expected.to include(
85
+ expect(subject).to include(
74
86
  " ---\n id: diffs1\n ---\n-text: diff2\n+text: diff\n",
75
87
  " ---\n id: diffs3\n ---\n-text: diff2\n+text: diff\n",
76
88
  " ---\n id: diffs2\n ---\n-text: diff2\n+text: diff\n"
@@ -79,14 +91,14 @@ describe DatadogBackup::Cli do
79
91
  end
80
92
 
81
93
  describe '#restore' do
82
- before(:example) do
94
+ subject { cli.restore }
95
+
96
+ before do
83
97
  dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs1.json")
84
98
  allow(dashboards).to receive(:get_by_id).and_return({ 'text' => 'diff2' })
85
99
  allow(cli).to receive(:initialize_client).and_return(client_double)
86
100
  end
87
101
 
88
- subject { cli.restore }
89
-
90
102
  example 'starts interactive restore' do
91
103
  allow($stdin).to receive(:gets).and_return('q')
92
104
 
@@ -101,21 +113,24 @@ describe DatadogBackup::Cli do
101
113
  expect(dashboards).to receive(:update).with('diffs1', { 'text' => 'diff' })
102
114
  subject
103
115
  end
116
+
104
117
  example 'download' do
105
118
  allow($stdin).to receive(:gets).and_return('d')
106
119
  expect(dashboards).to receive(:write_file).with(%({\n "text": "diff2"\n}), "#{tempdir}/dashboards/diffs1.json")
107
120
  subject
108
121
  end
122
+
109
123
  example 'skip' do
110
124
  allow($stdin).to receive(:gets).and_return('s')
111
- expect(dashboards).to_not receive(:write_file)
112
- expect(dashboards).to_not receive(:update)
125
+ expect(dashboards).not_to receive(:write_file)
126
+ expect(dashboards).not_to receive(:update)
113
127
  subject
114
128
  end
129
+
115
130
  example 'quit' do
116
131
  allow($stdin).to receive(:gets).and_return('q')
117
- expect(dashboards).to_not receive(:write_file)
118
- expect(dashboards).to_not receive(:update)
132
+ expect(dashboards).not_to receive(:write_file)
133
+ expect(dashboards).not_to receive(:update)
119
134
  expect { subject }.to raise_error(SystemExit)
120
135
  end
121
136
  end
@@ -7,7 +7,7 @@ describe DatadogBackup::Core do
7
7
  let(:client_double) { double }
8
8
  let(:tempdir) { Dir.mktmpdir }
9
9
  let(:core) do
10
- DatadogBackup::Core.new(
10
+ described_class.new(
11
11
  action: 'backup',
12
12
  api_service: api_service_double,
13
13
  client: client_double,
@@ -21,6 +21,7 @@ describe DatadogBackup::Core do
21
21
 
22
22
  describe '#client' do
23
23
  subject { core.client }
24
+
24
25
  it { is_expected.to eq client_double }
25
26
  end
26
27
 
@@ -41,14 +42,15 @@ describe DatadogBackup::Core do
41
42
  end
42
43
 
43
44
  describe '#diff' do
44
- before(:example) do
45
+ subject { core.diff('diff') }
46
+
47
+ before do
45
48
  allow(core).to receive(:get_by_id).and_return({ 'text' => 'diff1', 'extra' => 'diff1' })
46
49
  core.write_file('{"text": "diff2", "extra": "diff2"}', "#{tempdir}/core/diff.json")
47
50
  end
48
51
 
49
- subject { core.diff('diff') }
50
52
  it {
51
- is_expected.to eq <<~EOF
53
+ expect(subject).to eq <<~EOF
52
54
  ---
53
55
  -extra: diff1
54
56
  -text: diff1
@@ -60,11 +62,13 @@ describe DatadogBackup::Core do
60
62
 
61
63
  describe '#except' do
62
64
  subject { core.except({ a: :b, b: :c }) }
65
+
63
66
  it { is_expected.to eq({ a: :b, b: :c }) }
64
67
  end
65
68
 
66
69
  describe '#initialize' do
67
70
  subject { core }
71
+
68
72
  it 'makes the subdirectories' do
69
73
  expect(FileUtils).to receive(:mkdir_p).with("#{tempdir}/core")
70
74
  subject
@@ -73,60 +77,65 @@ describe DatadogBackup::Core do
73
77
 
74
78
  describe '#myclass' do
75
79
  subject { core.myclass }
80
+
76
81
  it { is_expected.to eq 'core' }
77
82
  end
78
83
 
79
84
  describe '#create' do
80
85
  subject { core.create({ 'a' => 'b' }) }
86
+
81
87
  example 'it calls Dogapi::APIService.request' do
82
88
  stub_const('Dogapi::APIService::API_VERSION', 'v1')
83
89
  allow(core).to receive(:api_service).and_return(api_service_double)
84
90
  allow(core).to receive(:api_version).and_return('v1')
85
91
  allow(core).to receive(:api_resource_name).and_return('dashboard')
86
- expect(api_service_double).to receive(:request).with(Net::HTTP::Post, '/api/v1/dashboard', nil, { 'a' => 'b' },
87
- true).and_return(['200', { 'id' => 'whatever-id-abc' }])
92
+ expect(api_service_double).to receive(:request).with(Net::HTTP::Post,
93
+ '/api/v1/dashboard',
94
+ nil,
95
+ { 'a' => 'b' },
96
+ true).and_return(['200', { 'id' => 'whatever-id-abc' }])
88
97
  subject
89
98
  end
90
99
  end
91
100
 
92
101
  describe '#update' do
93
102
  subject { core.update('abc-123-def', { 'a' => 'b' }) }
103
+
94
104
  example 'it calls Dogapi::APIService.request' do
95
105
  stub_const('Dogapi::APIService::API_VERSION', 'v1')
96
106
  allow(core).to receive(:api_service).and_return(api_service_double)
97
107
  allow(core).to receive(:api_version).and_return('v1')
98
108
  allow(core).to receive(:api_resource_name).and_return('dashboard')
99
- expect(api_service_double).to receive(:request).with(Net::HTTP::Put, '/api/v1/dashboard/abc-123-def', nil,
100
- { 'a' => 'b' }, true).and_return(['200',
101
- { 'id' => 'whataver-man-thats-like-your-opinion' }])
109
+ expect(api_service_double).to receive(:request).with(Net::HTTP::Put,
110
+ '/api/v1/dashboard/abc-123-def',
111
+ nil,
112
+ { 'a' => 'b' },
113
+ true).and_return(['200', { 'id' => 'whatever-id-abc' }])
102
114
  subject
103
115
  end
104
116
  end
105
117
 
106
118
  describe '#restore' do
107
- before(:each) do
119
+ before do
108
120
  allow(core).to receive(:api_service).and_return(api_service_double)
109
121
  allow(core).to receive(:api_version).and_return('api-version-string')
110
122
  allow(core).to receive(:api_resource_name).and_return('api-resource-name-string')
111
- allow(api_service_double).to receive(:request).with(
112
- Net::HTTP::Get,
113
- '/api/api-version-string/api-resource-name-string/abc-123-def',
114
- nil,
115
- nil,
116
- false
117
- ).and_return(['200', { test: :ok }])
118
- allow(api_service_double).to receive(:request).with(
119
- Net::HTTP::Get,
120
- '/api/api-version-string/api-resource-name-string/bad-123-id',
121
- nil,
122
- nil,
123
- false
124
- ).and_return(['404', { error: :blahblah_not_found }])
123
+ allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
124
+ '/api/api-version-string/api-resource-name-string/abc-123-def',
125
+ nil,
126
+ nil,
127
+ false).and_return(['200', { test: :ok }])
128
+ allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
129
+ '/api/api-version-string/api-resource-name-string/bad-123-id',
130
+ nil,
131
+ nil,
132
+ false).and_return(['404', { error: :blahblah_not_found }])
125
133
  allow(core).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
126
134
  end
127
135
 
128
136
  context 'when id exists' do
129
137
  subject { core.restore('abc-123-def') }
138
+
130
139
  example 'it calls out to update' do
131
140
  expect(core).to receive(:update).with('abc-123-def', { 'load' => 'ok' })
132
141
  subject
@@ -134,27 +143,20 @@ describe DatadogBackup::Core do
134
143
  end
135
144
 
136
145
  context 'when id does not exist' do
137
- before(:each) do
138
- allow(api_service_double).to receive(:request).with(
139
- Net::HTTP::Put,
140
- '/api/api-version-string/api-resource-name-string/bad-123-id',
141
- nil, { 'load' => 'ok' },
142
- true
143
- ).and_return(
144
- ['404', { 'Error' => 'my not found' }]
145
- )
146
- allow(api_service_double).to receive(:request).with(
147
- Net::HTTP::Post,
148
- '/api/api-version-string/api-resource-name-string',
149
- nil,
150
- { 'load' => 'ok' },
151
- true
152
- ).and_return(
153
- ['200', { 'id' => 'my-new-id' }]
154
- )
146
+ subject { core.restore('bad-123-id') }
147
+
148
+ before do
149
+ allow(api_service_double).to receive(:request).with(Net::HTTP::Put,
150
+ '/api/api-version-string/api-resource-name-string/bad-123-id',
151
+ nil, { 'load' => 'ok' },
152
+ true).and_return(['404', { 'Error' => 'my not found' }])
153
+ allow(api_service_double).to receive(:request).with(Net::HTTP::Post,
154
+ '/api/api-version-string/api-resource-name-string',
155
+ nil,
156
+ { 'load' => 'ok' },
157
+ true).and_return(['200', { 'id' => 'my-new-id' }])
155
158
  end
156
159
 
157
- subject { core.restore('bad-123-id') }
158
160
  example 'it calls out to create then saves the new file and deletes the new file' do
159
161
  expect(core).to receive(:create).with({ 'load' => 'ok' }).and_return({ 'id' => 'my-new-id' })
160
162
  expect(core).to receive(:get_and_write_file).with('my-new-id')
@@ -7,7 +7,7 @@ describe DatadogBackup::Dashboards do
7
7
  let(:client_double) { double }
8
8
  let(:tempdir) { Dir.mktmpdir }
9
9
  let(:dashboards) do
10
- DatadogBackup::Dashboards.new(
10
+ described_class.new(
11
11
  action: 'backup',
12
12
  client: client_double,
13
13
  backup_dir: tempdir,
@@ -59,7 +59,8 @@ describe DatadogBackup::Dashboards do
59
59
  'title' => 'example dashboard'
60
60
  }
61
61
  end
62
- before(:example) do
62
+
63
+ before do
63
64
  allow(client_double).to receive(:instance_variable_get).with(:@dashboard_service).and_return(api_service_double)
64
65
  allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/dashboard', nil, nil,
65
66
  false).and_return(all_boards)
@@ -108,11 +109,13 @@ describe DatadogBackup::Dashboards do
108
109
 
109
110
  describe '#except' do
110
111
  subject { dashboards.except({ :a => :b, 'modified_at' => :c, 'url' => :d }) }
112
+
111
113
  it { is_expected.to eq({ a: :b }) }
112
114
  end
113
115
 
114
116
  describe '#get_by_id' do
115
117
  subject { dashboards.get_by_id('abc-123-def') }
118
+
116
119
  it { is_expected.to eq board_abc_123_def }
117
120
  end
118
121
  end
@@ -27,55 +27,61 @@ describe DatadogBackup::LocalFilesystem do
27
27
  end
28
28
 
29
29
  describe '#all_files' do
30
- before(:example) do
30
+ subject { core.all_files }
31
+
32
+ before do
31
33
  File.new("#{tempdir}/all_files.json", 'w')
32
34
  end
33
35
 
34
- after(:example) do
36
+ after do
35
37
  FileUtils.rm "#{tempdir}/all_files.json"
36
38
  end
37
39
 
38
- subject { core.all_files }
39
40
  it { is_expected.to eq(["#{tempdir}/all_files.json"]) }
40
41
  end
41
42
 
42
43
  describe '#all_file_ids_for_selected_resources' do
43
- before(:example) do
44
+ subject { core.all_file_ids_for_selected_resources }
45
+
46
+ before do
44
47
  Dir.mkdir("#{tempdir}/dashboards")
45
48
  Dir.mkdir("#{tempdir}/monitors")
46
49
  File.new("#{tempdir}/dashboards/all_files.json", 'w')
47
50
  File.new("#{tempdir}/monitors/12345.json", 'w')
48
51
  end
49
52
 
50
- after(:example) do
53
+ after do
51
54
  FileUtils.rm "#{tempdir}/dashboards/all_files.json"
52
55
  FileUtils.rm "#{tempdir}/monitors/12345.json"
53
56
  end
54
57
 
55
- subject { core.all_file_ids_for_selected_resources }
56
58
  it { is_expected.to eq(['all_files']) }
57
59
  end
58
60
 
59
61
  describe '#class_from_id' do
60
- before(:example) do
62
+ subject { core.class_from_id('abc-123-def') }
63
+
64
+ before do
61
65
  core.write_file('abc', "#{tempdir}/core/abc-123-def.json")
62
66
  end
63
67
 
64
- after(:example) do
68
+ after do
65
69
  FileUtils.rm "#{tempdir}/core/abc-123-def.json"
66
70
  end
67
- subject { core.class_from_id('abc-123-def') }
71
+
68
72
  it { is_expected.to eq DatadogBackup::Core }
69
73
  end
70
74
 
71
75
  describe '#dump' do
72
76
  context ':json' do
73
77
  subject { core.dump({ a: :b }) }
78
+
74
79
  it { is_expected.to eq(%({\n "a": "b"\n})) }
75
80
  end
76
81
 
77
82
  context ':yaml' do
78
83
  subject { core_yaml.dump({ 'a' => 'b' }) }
84
+
79
85
  it { is_expected.to eq(%(---\na: b\n)) }
80
86
  end
81
87
  end
@@ -83,80 +89,94 @@ describe DatadogBackup::LocalFilesystem do
83
89
  describe '#filename' do
84
90
  context ':json' do
85
91
  subject { core.filename('abc-123-def') }
92
+
86
93
  it { is_expected.to eq("#{tempdir}/core/abc-123-def.json") }
87
94
  end
88
95
 
89
96
  context ':yaml' do
90
97
  subject { core_yaml.filename('abc-123-def') }
98
+
91
99
  it { is_expected.to eq("#{tempdir}/core/abc-123-def.yaml") }
92
100
  end
93
101
  end
94
102
 
95
103
  describe '#file_type' do
96
- before(:example) do
104
+ subject { core.file_type("#{tempdir}/file_type.json") }
105
+
106
+ before do
97
107
  File.new("#{tempdir}/file_type.json", 'w')
98
108
  end
99
109
 
100
- after(:example) do
110
+ after do
101
111
  FileUtils.rm "#{tempdir}/file_type.json"
102
112
  end
103
113
 
104
- subject { core.file_type("#{tempdir}/file_type.json") }
105
114
  it { is_expected.to eq :json }
106
115
  end
107
116
 
108
117
  describe '#find_file_by_id' do
109
- before(:example) do
118
+ subject { core.find_file_by_id('find_file') }
119
+
120
+ before do
110
121
  File.new("#{tempdir}/find_file.json", 'w')
111
122
  end
112
123
 
113
- after(:example) do
124
+ after do
114
125
  FileUtils.rm "#{tempdir}/find_file.json"
115
126
  end
116
127
 
117
- subject { core.find_file_by_id('find_file') }
118
128
  it { is_expected.to eq "#{tempdir}/find_file.json" }
119
129
  end
120
130
 
121
131
  describe '#load_from_file' do
122
132
  context ':json' do
123
133
  subject { core.load_from_file(%({\n "a": "b"\n}), :json) }
134
+
124
135
  it { is_expected.to eq('a' => 'b') }
125
136
  end
126
137
 
127
138
  context ':yaml' do
128
139
  subject { core.load_from_file(%(---\na: b\n), :yaml) }
140
+
129
141
  it { is_expected.to eq('a' => 'b') }
130
142
  end
131
143
  end
132
144
 
133
145
  describe '#load_from_file_by_id' do
134
146
  context 'written in json read in yaml mode' do
135
- before(:example) { core.write_file(%({"a": "b"}), "#{tempdir}/core/abc-123-def.json") }
136
- after(:example) { FileUtils.rm "#{tempdir}/core/abc-123-def.json" }
137
-
138
147
  subject { core_yaml.load_from_file_by_id('abc-123-def') }
148
+
149
+ before { core.write_file(%({"a": "b"}), "#{tempdir}/core/abc-123-def.json") }
150
+
151
+ after { FileUtils.rm "#{tempdir}/core/abc-123-def.json" }
152
+
139
153
  it { is_expected.to eq('a' => 'b') }
140
154
  end
141
- context 'written in yaml read in json mode' do
142
- before(:example) { core.write_file(%(---\na: b), "#{tempdir}/core/abc-123-def.yaml") }
143
- after(:example) { FileUtils.rm "#{tempdir}/core/abc-123-def.yaml" }
144
155
 
156
+ context 'written in yaml read in json mode' do
145
157
  subject { core.load_from_file_by_id('abc-123-def') }
158
+
159
+ before { core.write_file(%(---\na: b), "#{tempdir}/core/abc-123-def.yaml") }
160
+
161
+ after { FileUtils.rm "#{tempdir}/core/abc-123-def.yaml" }
162
+
146
163
  it { is_expected.to eq('a' => 'b') }
147
164
  end
148
165
 
149
166
  context 'Integer as parameter' do
150
- before(:example) { core.write_file(%(---\na: b), "#{tempdir}/core/12345.yaml") }
151
- after(:example) { FileUtils.rm "#{tempdir}/core/12345.yaml" }
152
-
153
167
  subject { core.load_from_file_by_id(12_345) }
168
+
169
+ before { core.write_file(%(---\na: b), "#{tempdir}/core/12345.yaml") }
170
+
171
+ after { FileUtils.rm "#{tempdir}/core/12345.yaml" }
172
+
154
173
  it { is_expected.to eq('a' => 'b') }
155
174
  end
156
175
  end
157
176
 
158
177
  describe '#write_file' do
159
178
  subject { core.write_file('abc123', "#{tempdir}/core/abc-123-def.json") }
179
+
160
180
  let(:file_like_object) { double }
161
181
 
162
182
  it 'writes a file to abc-123-def.json' do
@@ -7,7 +7,7 @@ describe DatadogBackup::Monitors do
7
7
  let(:client_double) { double }
8
8
  let(:tempdir) { Dir.mktmpdir }
9
9
  let(:monitors) do
10
- DatadogBackup::Monitors.new(
10
+ described_class.new(
11
11
  action: 'backup',
12
12
  client: client_double,
13
13
  backup_dir: tempdir,
@@ -49,7 +49,7 @@ describe DatadogBackup::Monitors do
49
49
  ]
50
50
  end
51
51
 
52
- before(:example) do
52
+ before do
53
53
  allow(client_double).to receive(:instance_variable_get).with(:@monitor_svc).and_return(api_service_double)
54
54
  allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/monitor', nil, nil,
55
55
  false).and_return(all_monitors)
@@ -59,6 +59,7 @@ describe DatadogBackup::Monitors do
59
59
 
60
60
  describe '#all_monitors' do
61
61
  subject { monitors.all_monitors }
62
+
62
63
  it { is_expected.to eq [monitor_description] }
63
64
  end
64
65
 
@@ -102,16 +103,20 @@ describe DatadogBackup::Monitors do
102
103
 
103
104
  describe '#filename' do
104
105
  subject { monitors.filename(123_455) }
106
+
105
107
  it { is_expected.to eq("#{tempdir}/monitors/123455.json") }
106
108
  end
107
109
 
108
110
  describe '#get_by_id' do
109
111
  context 'Integer' do
110
112
  subject { monitors.get_by_id(123_455) }
113
+
111
114
  it { is_expected.to eq monitor_description }
112
115
  end
116
+
113
117
  context 'String' do
114
118
  subject { monitors.get_by_id('123455') }
119
+
115
120
  it { is_expected.to eq monitor_description }
116
121
  end
117
122
  end
@@ -47,7 +47,7 @@ describe 'bin/datadog_backup' do
47
47
  it "dies unless given ENV[#{v}]" do
48
48
  ClimateControl.env[v] = nil
49
49
  _, status = run_bin('backup')
50
- expect(status).to_not be_success
50
+ expect(status).not_to be_success
51
51
  end
52
52
  end
53
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.1
4
+ version: 1.0.0.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kamran Farhadi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-17 00:00:00.000000000 Z
12
+ date: 2021-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amazing_print
@@ -135,6 +135,7 @@ files:
135
135
  - ".github/dependabot.yml"
136
136
  - ".github/workflows/rspec_and_release.yml"
137
137
  - ".gitignore"
138
+ - ".rubocop.yml"
138
139
  - CHANGELOG.md
139
140
  - CODE_OF_CONDUCT.md
140
141
  - Gemfile