stoplight 4.1.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +288 -354
- data/lib/stoplight/admin/actions/action.rb +24 -0
- data/lib/stoplight/admin/actions/lock.rb +23 -0
- data/lib/stoplight/admin/actions/lock_all_green.rb +18 -0
- data/lib/stoplight/admin/actions/lock_green.rb +23 -0
- data/lib/stoplight/admin/actions/lock_red.rb +23 -0
- data/lib/stoplight/admin/actions/stats.rb +27 -0
- data/lib/stoplight/admin/actions/unlock.rb +23 -0
- data/lib/stoplight/admin/dependencies.rb +50 -0
- data/lib/stoplight/admin/helpers.rb +27 -0
- data/lib/stoplight/admin/lights_repository/light.rb +155 -0
- data/lib/stoplight/admin/lights_repository.rb +74 -0
- data/lib/stoplight/admin/lights_stats.rb +77 -0
- data/lib/stoplight/admin/views/_card.erb +120 -0
- data/lib/stoplight/admin/views/index.erb +36 -0
- data/lib/stoplight/admin/views/layout.erb +66 -0
- data/lib/stoplight/admin.rb +68 -0
- data/lib/stoplight/color.rb +3 -3
- data/lib/stoplight/config/config_provider.rb +62 -0
- data/lib/stoplight/config/library_default_config.rb +29 -0
- data/lib/stoplight/config/user_default_config.rb +83 -0
- data/lib/stoplight/data_store/base.rb +59 -33
- data/lib/stoplight/data_store/fail_safe.rb +105 -0
- data/lib/stoplight/data_store/memory.rb +257 -50
- data/lib/stoplight/data_store/redis/get_metadata.lua +38 -0
- data/lib/stoplight/data_store/redis/lua.rb +23 -0
- data/lib/stoplight/data_store/redis/record_failure.lua +36 -0
- data/lib/stoplight/data_store/redis/record_success.lua +35 -0
- data/lib/stoplight/data_store/redis/transition_to_green.lua +10 -0
- data/lib/stoplight/data_store/redis/transition_to_red.lua +10 -0
- data/lib/stoplight/data_store/redis/transition_to_yellow.lua +9 -0
- data/lib/stoplight/data_store/redis.rb +345 -106
- data/lib/stoplight/default.rb +11 -9
- data/lib/stoplight/error.rb +1 -13
- data/lib/stoplight/failure.rb +14 -13
- data/lib/stoplight/light/config.rb +118 -0
- data/lib/stoplight/light/configuration_builder_interface.rb +128 -0
- data/lib/stoplight/light/green_run_strategy.rb +53 -0
- data/lib/stoplight/light/red_run_strategy.rb +26 -0
- data/lib/stoplight/light/run_strategy.rb +30 -0
- data/lib/stoplight/light/yellow_run_strategy.rb +78 -0
- data/lib/stoplight/light.rb +164 -84
- data/lib/stoplight/metadata.rb +71 -0
- data/lib/stoplight/notifier/base.rb +14 -7
- data/lib/stoplight/notifier/fail_safe.rb +67 -0
- data/lib/stoplight/notifier/generic.rb +54 -5
- data/lib/stoplight/rspec/generic_notifier.rb +11 -12
- data/lib/stoplight/rspec.rb +1 -1
- data/lib/stoplight/state.rb +3 -3
- data/lib/stoplight/traffic_control/base.rb +35 -0
- data/lib/stoplight/traffic_control/consecutive_failures.rb +43 -0
- data/lib/stoplight/traffic_recovery/base.rb +51 -0
- data/lib/stoplight/traffic_recovery/single_success.rb +35 -0
- data/lib/stoplight/version.rb +1 -1
- data/lib/stoplight.rb +111 -51
- metadata +49 -98
- data/lib/stoplight/builder.rb +0 -70
- data/lib/stoplight/circuit_breaker.rb +0 -102
- data/lib/stoplight/configurable.rb +0 -95
- data/lib/stoplight/configuration.rb +0 -126
- data/lib/stoplight/light/deprecated.rb +0 -44
- data/lib/stoplight/light/lockable.rb +0 -45
- data/lib/stoplight/light/runnable.rb +0 -127
- data/lib/stoplight/notifier.rb +0 -6
- data/spec/spec_helper.rb +0 -22
- data/spec/stoplight/builder_spec.rb +0 -165
- data/spec/stoplight/circuit_breaker_spec.rb +0 -43
- data/spec/stoplight/color_spec.rb +0 -39
- data/spec/stoplight/configurable_spec.rb +0 -25
- data/spec/stoplight/data_store/base_spec.rb +0 -71
- data/spec/stoplight/data_store/memory_spec.rb +0 -22
- data/spec/stoplight/data_store/redis_spec.rb +0 -45
- data/spec/stoplight/data_store_spec.rb +0 -9
- data/spec/stoplight/default_spec.rb +0 -80
- data/spec/stoplight/error_spec.rb +0 -39
- data/spec/stoplight/failure_spec.rb +0 -108
- data/spec/stoplight/light/lockable_spec.rb +0 -93
- data/spec/stoplight/light/runnable_spec.rb +0 -38
- data/spec/stoplight/light_spec.rb +0 -156
- data/spec/stoplight/notifier/base_spec.rb +0 -18
- data/spec/stoplight/notifier/generic_spec.rb +0 -50
- data/spec/stoplight/notifier/io_spec.rb +0 -41
- data/spec/stoplight/notifier/logger_spec.rb +0 -75
- data/spec/stoplight/notifier_spec.rb +0 -9
- data/spec/stoplight/state_spec.rb +0 -39
- data/spec/stoplight/version_spec.rb +0 -9
- data/spec/stoplight_spec.rb +0 -32
- data/spec/support/configurable.rb +0 -69
- data/spec/support/data_store/base/clear_failures.rb +0 -24
- data/spec/support/data_store/base/clear_state.rb +0 -20
- data/spec/support/data_store/base/get_all.rb +0 -44
- data/spec/support/data_store/base/get_failures.rb +0 -30
- data/spec/support/data_store/base/get_state.rb +0 -7
- data/spec/support/data_store/base/names.rb +0 -29
- data/spec/support/data_store/base/record_failures.rb +0 -70
- data/spec/support/data_store/base/set_state.rb +0 -15
- data/spec/support/data_store/base/with_notification_lock.rb +0 -27
- data/spec/support/data_store/base.rb +0 -21
- data/spec/support/database_cleaner.rb +0 -26
- data/spec/support/exception_helpers.rb +0 -9
- data/spec/support/light/runnable/color.rb +0 -79
- data/spec/support/light/runnable/run.rb +0 -247
- data/spec/support/light/runnable/state.rb +0 -31
- data/spec/support/light/runnable.rb +0 -5
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::Color do
|
6
|
-
it 'is a module' do
|
7
|
-
expect(described_class).to be_a(Module)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '::GREEN' do
|
11
|
-
it 'is a string' do
|
12
|
-
expect(Stoplight::Color::GREEN).to be_a(String)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'is frozen' do
|
16
|
-
expect(Stoplight::Color::GREEN).to be_frozen
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '::YELLOW' do
|
21
|
-
it 'is a string' do
|
22
|
-
expect(Stoplight::Color::YELLOW).to be_a(String)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'is frozen' do
|
26
|
-
expect(Stoplight::Color::YELLOW).to be_frozen
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '::RED' do
|
31
|
-
it 'is a string' do
|
32
|
-
expect(Stoplight::Color::RED).to be_a(String)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'is frozen' do
|
36
|
-
expect(Stoplight::Color::RED).to be_frozen
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::Configurable do
|
6
|
-
describe '#with' do
|
7
|
-
subject(:configurable) { configurable_class.new }
|
8
|
-
|
9
|
-
let(:configurable_class) do
|
10
|
-
Class.new do
|
11
|
-
include Stoplight::Configurable
|
12
|
-
|
13
|
-
def configuration
|
14
|
-
Stoplight::Configuration.new(name: 'foo')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'raises NotImplementedError' do
|
20
|
-
expect do
|
21
|
-
configurable.with_data_store(nil)
|
22
|
-
end.to raise_error(NotImplementedError)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::DataStore::Base do
|
6
|
-
let(:data_store) { described_class.new }
|
7
|
-
|
8
|
-
it 'is a class' do
|
9
|
-
expect(described_class).to be_a(Class)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#names' do
|
13
|
-
it 'is not implemented' do
|
14
|
-
expect { data_store.names }.to raise_error(NotImplementedError)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#get_all' do
|
19
|
-
it 'is not implemented' do
|
20
|
-
expect { data_store.get_all(nil) }.to raise_error(NotImplementedError)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#get_failures' do
|
25
|
-
it 'is not implemented' do
|
26
|
-
expect { data_store.get_failures(nil) }
|
27
|
-
.to raise_error(NotImplementedError)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#record_failure' do
|
32
|
-
it 'is not implemented' do
|
33
|
-
expect { data_store.record_failure(nil, nil) }
|
34
|
-
.to raise_error(NotImplementedError)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#clear_failures' do
|
39
|
-
it 'is not implemented' do
|
40
|
-
expect { data_store.clear_failures(nil) }
|
41
|
-
.to raise_error(NotImplementedError)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#get_state' do
|
46
|
-
it 'is not implemented' do
|
47
|
-
expect { data_store.get_state(nil) }.to raise_error(NotImplementedError)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#set_state' do
|
52
|
-
it 'is not implemented' do
|
53
|
-
expect { data_store.set_state(nil, nil) }
|
54
|
-
.to raise_error(NotImplementedError)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#clear_state' do
|
59
|
-
it 'is not implemented' do
|
60
|
-
expect { data_store.clear_state(nil) }
|
61
|
-
.to raise_error(NotImplementedError)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#with_notification_lock' do
|
66
|
-
it 'is not implemented' do
|
67
|
-
expect { data_store.with_notification_lock(nil, nil, nil) }
|
68
|
-
.to raise_error(NotImplementedError)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::DataStore::Memory do
|
6
|
-
let(:data_store) { described_class.new }
|
7
|
-
let(:light) { Stoplight::Light.new(name) {} }
|
8
|
-
let(:name) { ('a'..'z').to_a.shuffle.join }
|
9
|
-
let(:failure) { Stoplight::Failure.new('class', 'message', Time.new) }
|
10
|
-
let(:other) { Stoplight::Failure.new('class', 'message 2', Time.new) }
|
11
|
-
|
12
|
-
it_behaves_like 'Stoplight::DataStore::Base'
|
13
|
-
it_behaves_like 'Stoplight::DataStore::Base#names'
|
14
|
-
it_behaves_like 'Stoplight::DataStore::Base#get_failures'
|
15
|
-
it_behaves_like 'Stoplight::DataStore::Base#get_all'
|
16
|
-
it_behaves_like 'Stoplight::DataStore::Base#record_failure'
|
17
|
-
it_behaves_like 'Stoplight::DataStore::Base#clear_failures'
|
18
|
-
it_behaves_like 'Stoplight::DataStore::Base#get_state'
|
19
|
-
it_behaves_like 'Stoplight::DataStore::Base#set_state'
|
20
|
-
it_behaves_like 'Stoplight::DataStore::Base#clear_state'
|
21
|
-
it_behaves_like 'Stoplight::DataStore::Base#with_notification_lock'
|
22
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::DataStore::Redis, :redis do
|
6
|
-
let(:data_store) { described_class.new(redis, redlock: redlock) }
|
7
|
-
let(:redlock) { instance_double(Redlock::Client) }
|
8
|
-
let(:light) { Stoplight::Light.new(name) {} }
|
9
|
-
let(:name) { ('a'..'z').to_a.shuffle.join }
|
10
|
-
let(:failure) { Stoplight::Failure.new('class', 'message', Time.new - 60) }
|
11
|
-
let(:other) { Stoplight::Failure.new('class', 'message 2', Time.new) }
|
12
|
-
|
13
|
-
it_behaves_like 'Stoplight::DataStore::Base'
|
14
|
-
it_behaves_like 'Stoplight::DataStore::Base#names'
|
15
|
-
it_behaves_like 'Stoplight::DataStore::Base#get_all'
|
16
|
-
it_behaves_like 'Stoplight::DataStore::Base#record_failure'
|
17
|
-
it_behaves_like 'Stoplight::DataStore::Base#clear_failures'
|
18
|
-
it_behaves_like 'Stoplight::DataStore::Base#get_state'
|
19
|
-
it_behaves_like 'Stoplight::DataStore::Base#set_state'
|
20
|
-
it_behaves_like 'Stoplight::DataStore::Base#clear_state'
|
21
|
-
|
22
|
-
it_behaves_like 'Stoplight::DataStore::Base#get_failures' do
|
23
|
-
context 'when JSON is invalid' do
|
24
|
-
before do
|
25
|
-
light.with_error_notifier { |_error| }
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'handles it without an error' do
|
29
|
-
expect(failure).to receive(:to_json).and_return('invalid JSON')
|
30
|
-
|
31
|
-
expect { data_store.record_failure(light, failure) }
|
32
|
-
.to change { data_store.get_failures(light) }
|
33
|
-
.to([have_attributes(error_class: 'JSON::ParserError')])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it_behaves_like 'Stoplight::DataStore::Base#with_notification_lock' do
|
39
|
-
let(:lock_key) { "stoplight:v4:notification_lock:#{name}" }
|
40
|
-
|
41
|
-
before do
|
42
|
-
allow(redlock).to receive(:lock).with(lock_key, 2_000).and_yield
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::Default do
|
6
|
-
it 'is a module' do
|
7
|
-
expect(described_class).to be_a(Module)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '::COOL_OFF_TIME' do
|
11
|
-
it 'is a float' do
|
12
|
-
expect(Stoplight::Default::COOL_OFF_TIME).to be_a(Float)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '::DATA_STORE' do
|
17
|
-
it 'is a data store' do
|
18
|
-
expect(Stoplight::Default::DATA_STORE).to be_a(Stoplight::DataStore::Base)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '::ERROR_HANDLER' do
|
23
|
-
it 'is a proc' do
|
24
|
-
expect(Stoplight::Default::ERROR_HANDLER).to be_a(Proc)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'has an arity of 2' do
|
28
|
-
expect(Stoplight::Default::ERROR_HANDLER.arity).to eql(2)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '::ERROR_NOTIFIER' do
|
33
|
-
it 'is a proc' do
|
34
|
-
expect(Stoplight::Default::ERROR_NOTIFIER).to be_a(Proc)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'has an arity of 1' do
|
38
|
-
expect(Stoplight::Default::ERROR_NOTIFIER.arity).to eql(1)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '::FALLBACK' do
|
43
|
-
it 'is nil' do
|
44
|
-
expect(Stoplight::Default::FALLBACK).to eql(nil)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '::FORMATTER' do
|
49
|
-
it 'is a proc' do
|
50
|
-
expect(Stoplight::Default::FORMATTER).to be_a(Proc)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'has the same arity as #notify' do
|
54
|
-
notify = Stoplight::Notifier::Base.new.method(:notify)
|
55
|
-
expect(Stoplight::Default::FORMATTER.arity).to eql(notify.arity)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '::NOTIFIERS' do
|
60
|
-
it 'is an array' do
|
61
|
-
expect(Stoplight::Default::NOTIFIERS).to be_an(Array)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'contains notifiers' do
|
65
|
-
Stoplight::Default::NOTIFIERS.each do |notifier|
|
66
|
-
expect(notifier).to be_a(Stoplight::Notifier::Base)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'is frozen' do
|
71
|
-
expect(Stoplight::Default::NOTIFIERS).to be_frozen
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '::THRESHOLD' do
|
76
|
-
it 'is an integer' do
|
77
|
-
expect(Stoplight::Default::THRESHOLD).to be_a(Integer)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::Error do
|
6
|
-
it 'is a module' do
|
7
|
-
expect(described_class).to be_a(Module)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '::Base' do
|
11
|
-
it 'is a class' do
|
12
|
-
expect(Stoplight::Error::Base).to be_a(Class)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'is a subclass of StandardError' do
|
16
|
-
expect(Stoplight::Error::Base).to be < StandardError
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '::IncorrectColor' do
|
21
|
-
it 'is a class' do
|
22
|
-
expect(Stoplight::Error::IncorrectColor).to be_a(Class)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'is a subclass of StandardError' do
|
26
|
-
expect(Stoplight::Error::IncorrectColor).to be < StandardError
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '::RedLight' do
|
31
|
-
it 'is a class' do
|
32
|
-
expect(Stoplight::Error::RedLight).to be_a(Class)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'is a subclass of StandardError' do
|
36
|
-
expect(Stoplight::Error::RedLight).to be < Stoplight::Error::Base
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::Failure do
|
6
|
-
let(:error) { ZeroDivisionError.new('divided by 0') }
|
7
|
-
let(:error_class) { error.class.name }
|
8
|
-
let(:error_message) { error.message }
|
9
|
-
let(:time) { Time.new(2001, 2, 3, 4, 5, 6, '+07:08') }
|
10
|
-
let(:json) do
|
11
|
-
JSON.generate(
|
12
|
-
error: { class: error_class, message: error_message },
|
13
|
-
time: time.strftime('%Y-%m-%dT%H:%M:%S.%N%:z')
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'is a class' do
|
18
|
-
expect(described_class).to be_a(Class)
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '.from_error' do
|
22
|
-
it 'creates a failure' do
|
23
|
-
Timecop.freeze do
|
24
|
-
failure = described_class.from_error(error)
|
25
|
-
expect(failure.error_class).to eql(error_class)
|
26
|
-
expect(failure.error_message).to eql(error_message)
|
27
|
-
expect(failure.time).to eql(Time.new)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '.from_json' do
|
33
|
-
it 'parses JSON' do
|
34
|
-
failure = described_class.from_json(json)
|
35
|
-
expect(failure.error_class).to eql(error_class)
|
36
|
-
expect(failure.error_message).to eql(error_message)
|
37
|
-
expect(failure.time).to eql(time)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#==' do
|
42
|
-
it 'is true when they are equal' do
|
43
|
-
failure = described_class.new(error_class, error_message, time)
|
44
|
-
other = described_class.new(error_class, error_message, time)
|
45
|
-
expect(failure).to eq(other)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'is false when they have different error classes' do
|
49
|
-
failure = described_class.new(error_class, error_message, time)
|
50
|
-
other = described_class.new(nil, error_message, time)
|
51
|
-
expect(failure).to_not eq(other)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'is false when they have different error messages' do
|
55
|
-
failure = described_class.new(error_class, error_message, time)
|
56
|
-
other = described_class.new(error_class, nil, time)
|
57
|
-
expect(failure).to_not eq(other)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'is false when they have different times' do
|
61
|
-
failure = described_class.new(error_class, error_message, time)
|
62
|
-
other = described_class.new(error_class, error_message, nil)
|
63
|
-
expect(failure).to_not eq(other)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#error_class' do
|
68
|
-
it 'reads the error class' do
|
69
|
-
expect(described_class.new(error_class, nil, nil).error_class)
|
70
|
-
.to eql(error_class)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#error_message' do
|
75
|
-
it 'reads the error message' do
|
76
|
-
expect(described_class.new(nil, error_message, nil).error_message)
|
77
|
-
.to eql(error_message)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#time' do
|
82
|
-
it 'reads the time' do
|
83
|
-
expect(described_class.new(nil, nil, time).time).to eql(time)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe '#to_json' do
|
88
|
-
it 'generates JSON' do
|
89
|
-
expect(described_class.new(error_class, error_message, time).to_json)
|
90
|
-
.to eql(json)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'generates JSON with options' do
|
94
|
-
expect(described_class.new(error_class, error_message, time).to_json({}))
|
95
|
-
.to eql(json)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe '::TIME_FORMAT' do
|
100
|
-
it 'is a string' do
|
101
|
-
expect(described_class::TIME_FORMAT).to be_a(String)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'is frozen' do
|
105
|
-
expect(described_class::TIME_FORMAT).to be_frozen
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Stoplight::Light::Lockable do
|
6
|
-
subject(:light) { Stoplight::Light.new(name, &code) }
|
7
|
-
|
8
|
-
let(:code) { -> { code_result } }
|
9
|
-
let(:code_result) { random_string }
|
10
|
-
let(:name) { random_string }
|
11
|
-
|
12
|
-
def random_string
|
13
|
-
('a'..'z').to_a.sample(8).join
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#lock' do
|
17
|
-
let(:color) { Stoplight::Color::GREEN }
|
18
|
-
|
19
|
-
context 'with correct color' do
|
20
|
-
it 'returns the light' do
|
21
|
-
expect(light.lock(color)).to be_a Stoplight::Light
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with green color' do
|
25
|
-
let(:color) { Stoplight::Color::GREEN }
|
26
|
-
|
27
|
-
it 'locks green color' do
|
28
|
-
expect(light.data_store).to receive(:set_state).with(light, Stoplight::State::LOCKED_GREEN)
|
29
|
-
|
30
|
-
light.lock(color)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with red color' do
|
35
|
-
let(:color) { Stoplight::Color::RED }
|
36
|
-
|
37
|
-
it 'locks red color' do
|
38
|
-
expect(light.data_store).to receive(:set_state).with(light, Stoplight::State::LOCKED_RED)
|
39
|
-
|
40
|
-
light.lock(color)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'with incorrect color' do
|
46
|
-
let(:color) { 'incorrect-color' }
|
47
|
-
|
48
|
-
it 'raises Error::IncorrectColor error' do
|
49
|
-
expect { light.lock(color) }.to raise_error(Stoplight::Error::IncorrectColor)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'does not lock color' do
|
53
|
-
expect(light.data_store).to_not receive(:set_state)
|
54
|
-
|
55
|
-
suppress(Stoplight::Error::IncorrectColor) { light.lock(color) }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#unlock' do
|
61
|
-
it 'returns the light' do
|
62
|
-
expect(light.unlock).to be_a Stoplight::Light
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'with locked green light' do
|
66
|
-
before { light.lock(Stoplight::Color::GREEN) }
|
67
|
-
|
68
|
-
it 'unlocks light' do
|
69
|
-
expect(light.data_store).to receive(:set_state).with(light, Stoplight::State::UNLOCKED)
|
70
|
-
|
71
|
-
light.unlock
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'with locked red light' do
|
76
|
-
before { light.lock(Stoplight::Color::RED) }
|
77
|
-
|
78
|
-
it 'unlocks light' do
|
79
|
-
expect(light.data_store).to receive(:set_state).with(light, Stoplight::State::UNLOCKED)
|
80
|
-
|
81
|
-
light.unlock
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'with unlocked light' do
|
86
|
-
it 'unlocks light' do
|
87
|
-
expect(light.data_store).to receive(:set_state).with(light, Stoplight::State::UNLOCKED)
|
88
|
-
|
89
|
-
light.unlock
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
RSpec.describe Stoplight::Light::Runnable, :redis do
|
7
|
-
let(:failure) do
|
8
|
-
Stoplight::Failure.new(error.class.name, error.message, time)
|
9
|
-
end
|
10
|
-
let(:error) { error_class.new(error_message) }
|
11
|
-
let(:error_class) { Class.new(StandardError) }
|
12
|
-
let(:error_message) { random_string }
|
13
|
-
let(:time) { Time.new }
|
14
|
-
|
15
|
-
def random_string
|
16
|
-
('a'..'z').to_a.sample(8).join
|
17
|
-
end
|
18
|
-
|
19
|
-
before do
|
20
|
-
light.with_data_store(data_store)
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'with memory data store' do
|
24
|
-
let(:data_store) { Stoplight::DataStore::Memory.new }
|
25
|
-
|
26
|
-
it_behaves_like 'Stoplight::Light::Runnable#state'
|
27
|
-
it_behaves_like 'Stoplight::Light::Runnable#color'
|
28
|
-
it_behaves_like 'Stoplight::Light::Runnable#run'
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with redis data store', :redis do
|
32
|
-
let(:data_store) { Stoplight::DataStore::Redis.new(redis) }
|
33
|
-
|
34
|
-
it_behaves_like 'Stoplight::Light::Runnable#state'
|
35
|
-
it_behaves_like 'Stoplight::Light::Runnable#color'
|
36
|
-
it_behaves_like 'Stoplight::Light::Runnable#run'
|
37
|
-
end
|
38
|
-
end
|