datadog_backup 3.0.0.alpha.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_and_release.yml +6 -3
- data/.rubocop.yml +36 -77
- data/CHANGELOG.md +33 -0
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/bin/datadog_backup +6 -9
- data/datadog_backup.gemspec +3 -4
- data/lib/datadog_backup/cli.rb +47 -51
- data/lib/datadog_backup/core.rb +66 -38
- data/lib/datadog_backup/dashboards.rb +11 -8
- data/lib/datadog_backup/deprecations.rb +4 -5
- data/lib/datadog_backup/local_filesystem.rb +4 -5
- data/lib/datadog_backup/monitors.rb +5 -4
- data/lib/datadog_backup/options.rb +1 -0
- data/lib/datadog_backup/synthetics.rb +66 -0
- data/lib/datadog_backup/thread_pool.rb +1 -0
- data/lib/datadog_backup/version.rb +1 -1
- data/lib/datadog_backup.rb +2 -5
- data/release.config.js +4 -6
- data/spec/datadog_backup/cli_spec.rb +56 -41
- data/spec/datadog_backup/core_spec.rb +52 -31
- data/spec/datadog_backup/dashboards_spec.rb +17 -32
- data/spec/datadog_backup/deprecations_spec.rb +7 -9
- data/spec/datadog_backup/local_filesystem_spec.rb +12 -12
- data/spec/datadog_backup/monitors_spec.rb +13 -29
- data/spec/datadog_backup/synthetics_spec.rb +258 -0
- data/spec/datadog_backup_bin_spec.rb +17 -15
- data/spec/spec_helper.rb +4 -2
- metadata +12 -19
- data/spec/datadog_backup_spec.rb +0 -6
@@ -3,7 +3,9 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe DatadogBackup::Deprecations do
|
6
|
-
|
6
|
+
subject(:check) { described_class.check }
|
7
|
+
|
8
|
+
let(:logger) { instance_double(Logger) }
|
7
9
|
|
8
10
|
before do
|
9
11
|
stub_const('LOGGER', logger)
|
@@ -12,24 +14,20 @@ describe DatadogBackup::Deprecations do
|
|
12
14
|
|
13
15
|
%w[2.4.10 2.5.9 2.6.8].each do |ruby_version|
|
14
16
|
describe "#check#{ruby_version}" do
|
15
|
-
subject { described_class.check }
|
16
|
-
|
17
17
|
it 'does warn' do
|
18
18
|
stub_const('RUBY_VERSION', ruby_version)
|
19
|
-
|
20
|
-
|
19
|
+
check
|
20
|
+
expect(logger).to have_received(:warn).with(/ruby-#{ruby_version} is deprecated./)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
%w[2.7.4 3.0.4 3.1.2 3.2.0-preview1].each do |ruby_version|
|
26
26
|
describe "#check#{ruby_version}" do
|
27
|
-
subject { described_class.check }
|
28
|
-
|
29
27
|
it 'does not warn' do
|
30
28
|
stub_const('RUBY_VERSION', ruby_version)
|
31
|
-
|
32
|
-
|
29
|
+
check
|
30
|
+
expect(logger).not_to have_received(:warn).with(/ruby-#{ruby_version} is deprecated./)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -68,13 +68,13 @@ describe DatadogBackup::LocalFilesystem do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
describe '#dump' do
|
71
|
-
context ':json' do
|
71
|
+
context 'when mode is :json' do
|
72
72
|
subject { core.dump({ a: :b }) }
|
73
73
|
|
74
74
|
it { is_expected.to eq(%({\n "a": "b"\n})) }
|
75
75
|
end
|
76
76
|
|
77
|
-
context ':yaml' do
|
77
|
+
context 'when mode is :yaml' do
|
78
78
|
subject { core_yaml.dump({ 'a' => 'b' }) }
|
79
79
|
|
80
80
|
it { is_expected.to eq(%(---\na: b\n)) }
|
@@ -82,13 +82,13 @@ describe DatadogBackup::LocalFilesystem do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
describe '#filename' do
|
85
|
-
context ':json' do
|
85
|
+
context 'when mode is :json' do
|
86
86
|
subject { core.filename('abc-123-def') }
|
87
87
|
|
88
88
|
it { is_expected.to eq("#{tempdir}/core/abc-123-def.json") }
|
89
89
|
end
|
90
90
|
|
91
|
-
context ':yaml' do
|
91
|
+
context 'when mode is :yaml' do
|
92
92
|
subject { core_yaml.filename('abc-123-def') }
|
93
93
|
|
94
94
|
it { is_expected.to eq("#{tempdir}/core/abc-123-def.yaml") }
|
@@ -124,13 +124,13 @@ describe DatadogBackup::LocalFilesystem do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
describe '#load_from_file' do
|
127
|
-
context ':json' do
|
127
|
+
context 'when mode is :json' do
|
128
128
|
subject { core.load_from_file(%({\n "a": "b"\n}), :json) }
|
129
129
|
|
130
130
|
it { is_expected.to eq('a' => 'b') }
|
131
131
|
end
|
132
132
|
|
133
|
-
context ':yaml' do
|
133
|
+
context 'when mode is :yaml' do
|
134
134
|
subject { core.load_from_file(%(---\na: b\n), :yaml) }
|
135
135
|
|
136
136
|
it { is_expected.to eq('a' => 'b') }
|
@@ -138,7 +138,7 @@ describe DatadogBackup::LocalFilesystem do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
describe '#load_from_file_by_id' do
|
141
|
-
context '
|
141
|
+
context 'when the backup is in json but the mode is :yaml' do
|
142
142
|
subject { core_yaml.load_from_file_by_id('abc-123-def') }
|
143
143
|
|
144
144
|
before { core.write_file(%({"a": "b"}), "#{tempdir}/core/abc-123-def.json") }
|
@@ -148,7 +148,7 @@ describe DatadogBackup::LocalFilesystem do
|
|
148
148
|
it { is_expected.to eq('a' => 'b') }
|
149
149
|
end
|
150
150
|
|
151
|
-
context '
|
151
|
+
context 'when the backup is in yaml but the mode is :json' do
|
152
152
|
subject { core.load_from_file_by_id('abc-123-def') }
|
153
153
|
|
154
154
|
before { core.write_file(%(---\na: b), "#{tempdir}/core/abc-123-def.yaml") }
|
@@ -158,7 +158,7 @@ describe DatadogBackup::LocalFilesystem do
|
|
158
158
|
it { is_expected.to eq('a' => 'b') }
|
159
159
|
end
|
160
160
|
|
161
|
-
context 'Integer as parameter' do
|
161
|
+
context 'with Integer as parameter' do
|
162
162
|
subject { core.load_from_file_by_id(12_345) }
|
163
163
|
|
164
164
|
before { core.write_file(%(---\na: b), "#{tempdir}/core/12345.yaml") }
|
@@ -170,9 +170,9 @@ describe DatadogBackup::LocalFilesystem do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
describe '#write_file' do
|
173
|
-
subject { core.write_file('abc123', "#{tempdir}/core/abc-123-def.json") }
|
173
|
+
subject(:write_file) { core.write_file('abc123', "#{tempdir}/core/abc-123-def.json") }
|
174
174
|
|
175
|
-
let(:file_like_object) {
|
175
|
+
let(:file_like_object) { instance_double(File) }
|
176
176
|
|
177
177
|
it 'writes a file to abc-123-def.json' do
|
178
178
|
allow(File).to receive(:open).and_call_original
|
@@ -180,7 +180,7 @@ describe DatadogBackup::LocalFilesystem do
|
|
180
180
|
allow(file_like_object).to receive(:write)
|
181
181
|
allow(file_like_object).to receive(:close)
|
182
182
|
|
183
|
-
|
183
|
+
write_file
|
184
184
|
|
185
185
|
expect(file_like_object).to have_received(:write).with('abc123')
|
186
186
|
end
|
@@ -16,7 +16,6 @@ describe DatadogBackup::Monitors do
|
|
16
16
|
allow(monitors).to receive(:api_service).and_return(api_client_double)
|
17
17
|
return monitors
|
18
18
|
end
|
19
|
-
|
20
19
|
let(:monitor_description) do
|
21
20
|
{
|
22
21
|
'query' => 'bar',
|
@@ -35,30 +34,16 @@ describe DatadogBackup::Monitors do
|
|
35
34
|
'query' => 'bar'
|
36
35
|
}
|
37
36
|
end
|
38
|
-
let(:all_monitors)
|
39
|
-
|
40
|
-
200,
|
41
|
-
{},
|
42
|
-
[
|
43
|
-
monitor_description
|
44
|
-
]
|
45
|
-
]
|
46
|
-
end
|
47
|
-
let(:example_monitor) do
|
48
|
-
[
|
49
|
-
200,
|
50
|
-
{},
|
51
|
-
monitor_description
|
52
|
-
]
|
53
|
-
end
|
37
|
+
let(:all_monitors) { respond_with200([monitor_description]) }
|
38
|
+
let(:example_monitor) { respond_with200(monitor_description) }
|
54
39
|
|
55
40
|
before do
|
56
41
|
stubs.get('/api/v1/monitor') { all_monitors }
|
57
42
|
stubs.get('/api/v1/dashboard/123455') { example_monitor }
|
58
43
|
end
|
59
44
|
|
60
|
-
describe '#
|
61
|
-
subject { monitors.
|
45
|
+
describe '#get_all' do
|
46
|
+
subject { monitors.get_all }
|
62
47
|
|
63
48
|
it { is_expected.to eq [monitor_description] }
|
64
49
|
end
|
@@ -67,22 +52,21 @@ describe DatadogBackup::Monitors do
|
|
67
52
|
subject { monitors.backup }
|
68
53
|
|
69
54
|
it 'is expected to create a file' do
|
70
|
-
file =
|
55
|
+
file = instance_double(File)
|
71
56
|
allow(File).to receive(:open).with(monitors.filename(123_455), 'w').and_return(file)
|
72
|
-
|
57
|
+
allow(file).to receive(:write)
|
73
58
|
allow(file).to receive(:close)
|
74
59
|
|
75
60
|
monitors.backup
|
61
|
+
expect(file).to have_received(:write).with(::JSON.pretty_generate(clean_monitor_description))
|
76
62
|
end
|
77
63
|
end
|
78
64
|
|
79
65
|
describe '#diff and #except' do
|
80
66
|
example 'it ignores `overall_state` and `overall_state_modified`' do
|
81
67
|
monitors.write_file(monitors.dump(monitor_description), monitors.filename(123_455))
|
82
|
-
stubs.get('/api/v1/dashboard/123455')
|
83
|
-
|
84
|
-
200,
|
85
|
-
{},
|
68
|
+
stubs.get('/api/v1/dashboard/123455') do
|
69
|
+
respond_with200(
|
86
70
|
[
|
87
71
|
{
|
88
72
|
'query' => 'bar',
|
@@ -93,8 +77,8 @@ describe DatadogBackup::Monitors do
|
|
93
77
|
'overall_state_modified' => '9999-07-27T22:55:55+00:00'
|
94
78
|
}
|
95
79
|
]
|
96
|
-
|
97
|
-
|
80
|
+
)
|
81
|
+
end
|
98
82
|
|
99
83
|
expect(monitors.diff(123_455)).to eq ''
|
100
84
|
|
@@ -109,13 +93,13 @@ describe DatadogBackup::Monitors do
|
|
109
93
|
end
|
110
94
|
|
111
95
|
describe '#get_by_id' do
|
112
|
-
context 'Integer' do
|
96
|
+
context 'when Integer' do
|
113
97
|
subject { monitors.get_by_id(123_455) }
|
114
98
|
|
115
99
|
it { is_expected.to eq monitor_description }
|
116
100
|
end
|
117
101
|
|
118
|
-
context 'String' do
|
102
|
+
context 'when String' do
|
119
103
|
subject { monitors.get_by_id('123455') }
|
120
104
|
|
121
105
|
it { is_expected.to eq monitor_description }
|
@@ -0,0 +1,258 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DatadogBackup::Synthetics do
|
6
|
+
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
7
|
+
let(:api_client_double) { Faraday.new { |f| f.adapter :test, stubs } }
|
8
|
+
let(:tempdir) { Dir.mktmpdir } # TODO: delete afterward
|
9
|
+
let(:synthetics) do
|
10
|
+
synthetics = described_class.new(
|
11
|
+
action: 'backup',
|
12
|
+
backup_dir: tempdir,
|
13
|
+
output_format: :json,
|
14
|
+
resources: []
|
15
|
+
)
|
16
|
+
allow(synthetics).to receive(:api_service).and_return(api_client_double)
|
17
|
+
return synthetics
|
18
|
+
end
|
19
|
+
let(:api_test) do
|
20
|
+
{ 'config' => { 'assertions' => [{ 'operator' => 'contains', 'property' => 'set-cookie', 'target' => '_user_id', 'type' => 'header' },
|
21
|
+
{ 'operator' => 'contains', 'target' => 'body message', 'type' => 'body' },
|
22
|
+
{ 'operator' => 'is', 'property' => 'content-type', 'target' => 'text/html; charset=utf-8', 'type' => 'header' },
|
23
|
+
{ 'operator' => 'is', 'target' => 200, 'type' => 'statusCode' },
|
24
|
+
{ 'operator' => 'lessThan', 'target' => 5000, 'type' => 'responseTime' }],
|
25
|
+
'request' => { 'headers' => { 'User-Agent' => 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0',
|
26
|
+
'cookie' => '_a=12345; _example_session=abc123' },
|
27
|
+
'method' => 'GET',
|
28
|
+
'url' => 'https://www.example.com/' } },
|
29
|
+
'creator' => { 'email' => 'user@example.com', 'handle' => 'user@example.com', 'name' => 'Hugh Zer' },
|
30
|
+
'locations' => ['aws:ap-northeast-1', 'aws:eu-central-1', 'aws:eu-west-2', 'aws:us-west-2'],
|
31
|
+
'message' => 'TEST: This is a test',
|
32
|
+
'monitor_id' => 12_345,
|
33
|
+
'name' => 'TEST: This is a test',
|
34
|
+
'options' => { 'follow_redirects' => true,
|
35
|
+
'httpVersion' => 'http1',
|
36
|
+
'min_failure_duration' => 120,
|
37
|
+
'min_location_failed' => 2,
|
38
|
+
'monitor_options' => { 'renotify_interval' => 0 },
|
39
|
+
'monitor_priority' => 1,
|
40
|
+
'retry' => { 'count' => 1, 'interval' => 500 },
|
41
|
+
'tick_every' => 120 },
|
42
|
+
'public_id' => 'abc-123-def',
|
43
|
+
'status' => 'live',
|
44
|
+
'subtype' => 'http',
|
45
|
+
'tags' => ['env:test'],
|
46
|
+
'type' => 'api' }
|
47
|
+
end
|
48
|
+
let(:browser_test) do
|
49
|
+
{ 'config' => { 'assertions' => [],
|
50
|
+
'configVariables' => [],
|
51
|
+
'request' => { 'headers' => {}, 'method' => 'GET', 'url' => 'https://www.example.com' },
|
52
|
+
'setCookie' => nil,
|
53
|
+
'variables' => [] },
|
54
|
+
'creator' => { 'email' => 'user@example.com',
|
55
|
+
'handle' => 'user@example.com',
|
56
|
+
'name' => 'Hugh Zer' },
|
57
|
+
'locations' => ['aws:us-east-2'],
|
58
|
+
'message' => 'Test message',
|
59
|
+
'monitor_id' => 12_345,
|
60
|
+
'name' => 'www.example.com',
|
61
|
+
'options' => { 'ci' => { 'executionRule' => 'non_blocking' },
|
62
|
+
'device_ids' => ['chrome.laptop_large', 'chrome.mobile_small'],
|
63
|
+
'disableCors' => false,
|
64
|
+
'disableCsp' => false,
|
65
|
+
'ignoreServerCertificateError' => false,
|
66
|
+
'min_failure_duration' => 300,
|
67
|
+
'min_location_failed' => 1,
|
68
|
+
'monitor_options' => { 'renotify_interval' => 0 },
|
69
|
+
'noScreenshot' => false,
|
70
|
+
'retry' => { 'count' => 0, 'interval' => 1000 },
|
71
|
+
'tick_every' => 900 },
|
72
|
+
'public_id' => '456-ghi-789',
|
73
|
+
'status' => 'live',
|
74
|
+
'tags' => ['env:test'],
|
75
|
+
'type' => 'browser' }
|
76
|
+
end
|
77
|
+
let(:all_synthetics) { respond_with200({ 'tests' => [api_test, browser_test] }) }
|
78
|
+
let(:api_synthetic) { respond_with200(api_test) }
|
79
|
+
let(:browser_synthetic) { respond_with200(browser_test) }
|
80
|
+
|
81
|
+
before do
|
82
|
+
stubs.get('/api/v1/synthetics/tests') { all_synthetics }
|
83
|
+
stubs.get('/api/v1/synthetics/tests/api/abc-123-def') { api_synthetic }
|
84
|
+
stubs.get('/api/v1/synthetics/tests/browser/456-ghi-789') { browser_synthetic }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#all' do
|
88
|
+
subject { synthetics.all }
|
89
|
+
|
90
|
+
it { is_expected.to contain_exactly(api_test, browser_test) }
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#backup' do
|
94
|
+
subject(:backup) { synthetics.backup }
|
95
|
+
|
96
|
+
let(:apifile) { instance_double(File) }
|
97
|
+
let(:browserfile) { instance_double(File) }
|
98
|
+
|
99
|
+
before do
|
100
|
+
allow(File).to receive(:open).with(synthetics.filename('abc-123-def'), 'w').and_return(apifile)
|
101
|
+
allow(File).to receive(:open).with(synthetics.filename('456-ghi-789'), 'w').and_return(browserfile)
|
102
|
+
allow(apifile).to receive(:write)
|
103
|
+
allow(apifile).to receive(:close)
|
104
|
+
allow(browserfile).to receive(:write)
|
105
|
+
allow(browserfile).to receive(:close)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'is expected to write the API test' do
|
109
|
+
backup
|
110
|
+
expect(apifile).to have_received(:write).with(::JSON.pretty_generate(api_test))
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'is expected to write the browser test' do
|
114
|
+
backup
|
115
|
+
expect(browserfile).to have_received(:write).with(::JSON.pretty_generate(browser_test))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#filename' do
|
120
|
+
subject { synthetics.filename('abc-123-def') }
|
121
|
+
|
122
|
+
it { is_expected.to eq("#{tempdir}/synthetics/abc-123-def.json") }
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#get_by_id' do
|
126
|
+
context 'when the type is api' do
|
127
|
+
subject { synthetics.get_by_id('abc-123-def') }
|
128
|
+
|
129
|
+
it { is_expected.to eq api_test }
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when the type is browser' do
|
133
|
+
subject { synthetics.get_by_id('456-ghi-789') }
|
134
|
+
|
135
|
+
it { is_expected.to eq browser_test }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#diff' do # TODO: migrate to core_spec.rb, since #diff is not defined here.
|
140
|
+
subject { synthetics.diff('abc-123-def') }
|
141
|
+
|
142
|
+
before do
|
143
|
+
synthetics.write_file(synthetics.dump(api_test), synthetics.filename('abc-123-def'))
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'when the test is identical' do
|
147
|
+
it { is_expected.to be_empty }
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when the remote is not found' do
|
151
|
+
subject(:invalid_diff) { synthetics.diff('invalid-id') }
|
152
|
+
|
153
|
+
before do
|
154
|
+
synthetics.write_file(synthetics.dump({ 'name' => 'invalid-diff' }), synthetics.filename('invalid-id'))
|
155
|
+
end
|
156
|
+
|
157
|
+
it {
|
158
|
+
expect(invalid_diff).to eq(%(---- {}\n+---\n+name: invalid-diff))
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'when there is a local update' do
|
163
|
+
before do
|
164
|
+
different_test = api_test.dup
|
165
|
+
different_test['message'] = 'Different message'
|
166
|
+
synthetics.write_file(synthetics.dump(different_test), synthetics.filename('abc-123-def'))
|
167
|
+
end
|
168
|
+
|
169
|
+
it { is_expected.to include(%(-message: 'TEST: This is a test'\n+message: Different message)) }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#create' do
|
174
|
+
context 'when the type is api' do
|
175
|
+
subject(:create) { synthetics.create({ 'type' => 'api' }) }
|
176
|
+
|
177
|
+
before do
|
178
|
+
stubs.post('/api/v1/synthetics/tests/api') { respond_with200({ 'public_id' => 'api-create-abc' }) }
|
179
|
+
end
|
180
|
+
|
181
|
+
it { is_expected.to eq({ 'public_id' => 'api-create-abc' }) }
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when the type is browser' do
|
185
|
+
subject(:create) { synthetics.create({ 'type' => 'browser' }) }
|
186
|
+
|
187
|
+
before do
|
188
|
+
stubs.post('/api/v1/synthetics/tests/browser') { respond_with200({ 'public_id' => 'browser-create-abc' }) }
|
189
|
+
end
|
190
|
+
|
191
|
+
it { is_expected.to eq({ 'public_id' => 'browser-create-abc' }) }
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '#update' do
|
196
|
+
context 'when the type is api' do
|
197
|
+
subject(:update) { synthetics.update('api-update-abc', { 'type' => 'api' }) }
|
198
|
+
|
199
|
+
before do
|
200
|
+
stubs.put('/api/v1/synthetics/tests/api/api-update-abc') { respond_with200({ 'public_id' => 'api-update-abc' }) }
|
201
|
+
end
|
202
|
+
|
203
|
+
it { is_expected.to eq({ 'public_id' => 'api-update-abc' }) }
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when the type is browser' do
|
207
|
+
subject(:update) { synthetics.update('browser-update-abc', { 'type' => 'browser' }) }
|
208
|
+
|
209
|
+
before do
|
210
|
+
stubs.put('/api/v1/synthetics/tests/browser/browser-update-abc') { respond_with200({ 'public_id' => 'browser-update-abc' }) }
|
211
|
+
end
|
212
|
+
|
213
|
+
it { is_expected.to eq({ 'public_id' => 'browser-update-abc' }) }
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '#restore' do
|
218
|
+
context 'when the id exists' do
|
219
|
+
subject { synthetics.restore('abc-123-def') }
|
220
|
+
|
221
|
+
before do
|
222
|
+
synthetics.write_file(synthetics.dump({ 'name' => 'restore-valid-id', 'type' => 'api' }), synthetics.filename('abc-123-def'))
|
223
|
+
stubs.put('/api/v1/synthetics/tests/api/abc-123-def') { respond_with200({ 'public_id' => 'abc-123-def', 'type' => 'api' }) }
|
224
|
+
end
|
225
|
+
|
226
|
+
it { is_expected.to eq({ 'public_id' => 'abc-123-def', 'type' => 'api' }) }
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'when the id does not exist' do
|
230
|
+
subject(:restore) { synthetics.restore('restore-invalid-id') }
|
231
|
+
|
232
|
+
before do
|
233
|
+
synthetics.write_file(synthetics.dump({ 'name' => 'restore-invalid-id', 'type' => 'api' }), synthetics.filename('restore-invalid-id'))
|
234
|
+
stubs.put('/api/v1/synthetics/tests/api/restore-invalid-id') { [404, {}, ''] }
|
235
|
+
stubs.post('/api/v1/synthetics/tests/api') { respond_with200({ 'public_id' => 'restore-valid-id' }) }
|
236
|
+
allow(synthetics).to receive(:create).and_call_original
|
237
|
+
allow(synthetics).to receive(:all).and_return([api_test, browser_test, { 'public_id' => 'restore-valid-id', 'type' => 'api' }])
|
238
|
+
end
|
239
|
+
|
240
|
+
it { is_expected.to eq({ 'type' => 'api' }) }
|
241
|
+
|
242
|
+
it 'calls create with the contents of the original file' do
|
243
|
+
restore
|
244
|
+
expect(synthetics).to have_received(:create).with({ 'name' => 'restore-invalid-id', 'type' => 'api' })
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'deletes the original file' do
|
248
|
+
restore
|
249
|
+
expect(File.exist?(synthetics.filename('restore-invalid-id'))).to be false
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'creates a new file with the restored contents' do
|
253
|
+
restore
|
254
|
+
expect(File.exist?(synthetics.filename('restore-valid-id'))).to be true
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
@@ -3,20 +3,15 @@
|
|
3
3
|
require 'open3'
|
4
4
|
require 'timeout'
|
5
5
|
|
6
|
-
describe 'bin/datadog_backup' do
|
6
|
+
describe 'bin/datadog_backup' do # rubocop:disable RSpec/DescribeClass
|
7
7
|
# Contract Or[nil,String] => self
|
8
|
-
def run_bin(
|
8
|
+
def run_bin(env = {}, args = '')
|
9
9
|
status = nil
|
10
10
|
output = ''
|
11
11
|
cmd = "bin/datadog_backup #{args}"
|
12
|
-
Open3.popen2e(cmd) do |
|
12
|
+
Open3.popen2e(env, cmd) do |_i, oe, t|
|
13
13
|
pid = t.pid
|
14
14
|
|
15
|
-
if input
|
16
|
-
i.puts input
|
17
|
-
i.close
|
18
|
-
end
|
19
|
-
|
20
15
|
Timeout.timeout(4.0) do
|
21
16
|
oe.each do |v|
|
22
17
|
output += v
|
@@ -43,16 +38,23 @@ describe 'bin/datadog_backup' do
|
|
43
38
|
|
44
39
|
required_vars.map do |v|
|
45
40
|
it "dies unless given ENV[#{v}]" do
|
46
|
-
|
47
|
-
_, status = run_bin('backup')
|
41
|
+
myenv = env.dup.tap { |h| h.delete(v) }
|
42
|
+
_, status = run_bin(myenv, 'backup')
|
48
43
|
expect(status).not_to be_success
|
49
44
|
end
|
50
45
|
end
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
describe 'help' do
|
48
|
+
subject(:bin) { run_bin(env, '--help') }
|
49
|
+
|
50
|
+
it 'prints usage' do
|
51
|
+
out_err, _status = bin
|
52
|
+
expect(out_err).to match(/Usage: DD_API_KEY=/)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'exits cleanly' do
|
56
|
+
_out_err, status = bin
|
57
|
+
expect(status).to be_success
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,8 +11,6 @@ $stdout = File.new('/dev/null', 'w+')
|
|
11
11
|
require 'tmpdir'
|
12
12
|
require 'datadog_backup'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
14
|
SPEC_ROOT = __dir__
|
17
15
|
WORK_ROOT = File.expand_path(File.join(SPEC_ROOT, '..'))
|
18
16
|
|
@@ -38,3 +36,7 @@ RSpec.configure do |config|
|
|
38
36
|
|
39
37
|
Kernel.srand config.seed
|
40
38
|
end
|
39
|
+
|
40
|
+
def respond_with200(body)
|
41
|
+
[200, {}, body]
|
42
|
+
end
|
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: 3.
|
4
|
+
version: 3.1.0
|
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: 2022-08-
|
12
|
+
date: 2022-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: amazing_print
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: guard-rspec
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
@@ -124,7 +124,7 @@ dependencies:
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name: pry
|
127
|
+
name: pry
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ">="
|
@@ -138,7 +138,7 @@ dependencies:
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
141
|
+
name: pry-byebug
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- lib/datadog_backup/local_filesystem.rb
|
231
231
|
- lib/datadog_backup/monitors.rb
|
232
232
|
- lib/datadog_backup/options.rb
|
233
|
+
- lib/datadog_backup/synthetics.rb
|
233
234
|
- lib/datadog_backup/thread_pool.rb
|
234
235
|
- lib/datadog_backup/version.rb
|
235
236
|
- release.config.js
|
@@ -239,13 +240,14 @@ files:
|
|
239
240
|
- spec/datadog_backup/deprecations_spec.rb
|
240
241
|
- spec/datadog_backup/local_filesystem_spec.rb
|
241
242
|
- spec/datadog_backup/monitors_spec.rb
|
243
|
+
- spec/datadog_backup/synthetics_spec.rb
|
242
244
|
- spec/datadog_backup_bin_spec.rb
|
243
|
-
- spec/datadog_backup_spec.rb
|
244
245
|
- spec/spec_helper.rb
|
245
246
|
homepage: https://github.com/scribd/datadog_backup
|
246
247
|
licenses:
|
247
248
|
- MIT
|
248
|
-
metadata:
|
249
|
+
metadata:
|
250
|
+
rubygems_mfa_required: 'true'
|
249
251
|
post_install_message:
|
250
252
|
rdoc_options: []
|
251
253
|
require_paths:
|
@@ -257,21 +259,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
259
|
version: '2.7'
|
258
260
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
261
|
requirements:
|
260
|
-
- - "
|
262
|
+
- - ">="
|
261
263
|
- !ruby/object:Gem::Version
|
262
|
-
version:
|
264
|
+
version: '0'
|
263
265
|
requirements: []
|
264
266
|
rubygems_version: 3.1.6
|
265
267
|
signing_key:
|
266
268
|
specification_version: 4
|
267
269
|
summary: A utility to backup and restore Datadog accounts
|
268
|
-
test_files:
|
269
|
-
- spec/datadog_backup/cli_spec.rb
|
270
|
-
- spec/datadog_backup/core_spec.rb
|
271
|
-
- spec/datadog_backup/dashboards_spec.rb
|
272
|
-
- spec/datadog_backup/deprecations_spec.rb
|
273
|
-
- spec/datadog_backup/local_filesystem_spec.rb
|
274
|
-
- spec/datadog_backup/monitors_spec.rb
|
275
|
-
- spec/datadog_backup_bin_spec.rb
|
276
|
-
- spec/datadog_backup_spec.rb
|
277
|
-
- spec/spec_helper.rb
|
270
|
+
test_files: []
|