-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(state): Adds State Management component specs
- Loading branch information
Showing
3 changed files
with
119 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"timestamp":1728408645,"command_name":"Unit Tests","files":[{"filename":"/home/bougyman/rubyists/dapr/lib/dapr.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,null,1,1,5,null,null,null,1,1,1,1,1,null,null]},"covered_strength":1.4,"covered_lines":10,"lines_of_code":10},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,1,1,1,null,1,1,null,1,1,1,1,1,null,1,4,null,1,1,null,null,1,9,null,null,1,1,null,null,1,12,null,null,null,1,1,null,1,5,null,null,1,1,1,1,null,1,null,null,1,1,null,null,null,null,null]},"covered_strength":1.7878787878787878,"covered_lines":33,"lines_of_code":33},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/configuration.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,null,1,1,1,null,1,null,1,1,null,null,1,null,null,1,null,1,1,null,1,1,1,null,null,null,null,null,null,null,1,1,1,1,null,null,1,1,1,null,null,null,null,null]},"covered_strength":1.0,"covered_lines":21,"lines_of_code":21},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/lock.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,1,1,1,null,1,null,1,1,null,null,1,null,null,1,null,1,1,null,null,null,null,null,null,1,6,6,null,null,null,null,null,null,1,6,6,null,null,null,1,6,6,5,5,null,null,1,null,null,null,1,4,4,4,null,3,3,null,null,1,null,null,1,18,null,null,null,null,null,1,6,null,null,null,null,null]},"covered_strength":3.085714285714286,"covered_lines":35,"lines_of_code":35},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/version.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,1,null,null,null]},"covered_strength":1.0,"covered_lines":3,"lines_of_code":3}],"metrics":{"covered_percent":100.0,"covered_strength":2.0098039215686274,"covered_lines":102,"total_lines":102}} | ||
{"timestamp":1729718516,"command_name":"Unit Tests","files":[{"filename":"/home/bougyman/rubyists/dapr/lib/dapr.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,null,1,1,7,null,null,null,1,1,1,1,1,null,null]},"covered_strength":1.6,"covered_lines":10,"lines_of_code":10},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,1,1,1,null,1,1,null,1,1,1,1,1,1,null,1,4,null,1,1,null,null,1,11,null,null,1,1,null,null,1,14,null,null,null,1,1,null,1,5,null,null,1,1,1,1,null,1,null,null,1,1,null,null,null,null,null]},"covered_strength":1.8823529411764706,"covered_lines":34,"lines_of_code":34},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/configuration.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,null,1,1,1,null,1,null,1,1,null,null,1,null,null,1,null,1,1,null,1,1,1,null,null,null,null,null,null,null,1,1,1,1,null,null,1,1,1,null,null,null,null,null]},"covered_strength":1.0,"covered_lines":21,"lines_of_code":21},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/lock.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,1,1,1,null,1,null,1,1,null,null,1,null,null,1,null,1,1,null,null,null,null,null,null,1,6,6,null,null,null,null,null,null,1,6,6,null,null,null,1,6,6,5,5,null,null,1,null,null,null,1,4,4,4,null,3,3,null,null,1,null,null,1,18,null,null,null,null,null,1,6,null,null,null,null,null]},"covered_strength":3.085714285714286,"covered_lines":35,"lines_of_code":35},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/state.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,null,1,1,1,null,null,1,null,1,1,null,1,null,1,1,1,1,1,1,null,null,null,null,null,null,1,1,null,null,null,null,null,null,null,1,1,null,null,null,null,null,1,2,null,null,null,null,null,null,1,1,1,1,null,null,null,null,1,3,1,1,1,null,null,null,null,null]},"covered_strength":1.103448275862069,"covered_lines":29,"lines_of_code":29},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/version.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,1,null,null,null]},"covered_strength":1.0,"covered_lines":3,"lines_of_code":3}],"metrics":{"covered_percent":100.0,"covered_strength":1.8484848484848484,"covered_lines":132,"total_lines":132}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
# Tests for the Dapr State Management component | ||
class TestDaprState < Minitest::Test | ||
require Rubyists::Dapr::LIBROOT / :client / :state | ||
DummyClient = Rubyists::Dapr::Client::DummyClient | ||
Runtime = ::Dapr::Proto::Runtime::V1 | ||
Common = ::Dapr::Proto::Common::V1 | ||
Empty = Google::Protobuf::Empty | ||
|
||
def setup_dummy_client! | ||
DummyClient.define_method(:states) { @states ||= {} } | ||
define_get_bulk_state_method! | ||
define_set_bulk_state_method! | ||
end | ||
|
||
def define_get_bulk_state_method! | ||
DummyClient.define_method(:get_bulk_state) do |*args, &_block| | ||
items = args.shift.keys.map.with_index do |key, index| | ||
metadata = { key: "METAKEY-#{index}", value: "METAVALUE-#{index}" } | ||
data = "test-state-data-#{index}" | ||
Runtime::BulkStateItem.new(key:, data:, etag: '1', error: nil, metadata:) | ||
end | ||
Runtime::GetBulkStateResponse.new(items:) | ||
end | ||
end | ||
|
||
def define_set_bulk_state_method! | ||
DummyClient.define_method(:save_state) do |*args, &_block| | ||
args.shift.states.map { |s| states[s.key] = s.value } | ||
Empty | ||
end | ||
end | ||
|
||
def make_it_testy! | ||
return if testy? | ||
|
||
setup_dummy_client! | ||
@testy = true | ||
end | ||
|
||
def testy? | ||
@testy | ||
end | ||
|
||
context 'State' do # rubocop:disable Metrics/BlockLength | ||
should 'Read existing State item' do | ||
make_it_testy! | ||
messages = semantic_logger_events(Rubyists::Dapr::Client::State) do | ||
states = Rubyists::Dapr::Client::State.get('test_item1', 'test_item2') | ||
|
||
assert_equal 2, states.size | ||
assert_equal 'test-state-data-0', states[0].data | ||
assert_equal 'test_item1', states[0].key | ||
assert_equal 'test_item2', states[1].key | ||
assert_equal 'test-state-data-1', states[1].data | ||
end | ||
|
||
assert_equal 1, messages.size | ||
assert_semantic_logger_event messages.first, level: :debug, message: 'Getting state' | ||
refute_nil messages.first.payload[:keys] | ||
end | ||
|
||
should 'Set a State item' do | ||
make_it_testy! | ||
messages = semantic_logger_events(Rubyists::Dapr::Client::State) do | ||
items = { 'test_item1' => 'test-state-data-writes-0', 'test_item2' => 'test-state-data-writes-1' } | ||
response = Rubyists::Dapr::Client::State.set(items) | ||
|
||
assert_equal Empty, response | ||
end | ||
|
||
assert_equal 1, messages.size | ||
assert_semantic_logger_event messages.first, level: :debug, message: 'Setting state' | ||
assert_equal [{ key: 'test_item1', value: 'test-state-data-writes-0', metadata: {} }, | ||
{ key: 'test_item2', value: 'test-state-data-writes-1', metadata: {} }], | ||
messages.first.payload[:states] | ||
end | ||
end | ||
end |