Skip to content

Commit

Permalink
get_all_values
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-cat committed Mar 31, 2022
1 parent 7791140 commit 3af77ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/configcat/configcatclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ def get_key_and_value(variation_id)
end
end

def get_all_values(user: nil)
keys = get_all_keys()
all_values = {}
for key in keys
value = get_value(key, nil, user)
if !value.equal?(nil)
all_values[key] = value
end
end
return all_values
end

def force_refresh()
@_cache_policy.force_refresh()
end
Expand Down
30 changes: 30 additions & 0 deletions spec/configcat/configcatclient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ConfigCatClient.new(nil)
}.to raise_error(ConfigCatClientException)
end

it "test_bool" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -18,6 +19,7 @@
expect(client.get_value("testBoolKey", false)).to eq true
client.stop()
end

it "test_string" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -28,6 +30,7 @@
expect(client.get_value("testStringKey", "default")).to eq "testValue"
client.stop()
end

it "test_int" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -38,6 +41,7 @@
expect(client.get_value("testIntKey", 0)).to eq 1
client.stop()
end

it "test_double" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -48,6 +52,7 @@
expect(client.get_value("testDoubleKey", 0.0)).to eq 1.1
client.stop()
end

it "test_unknown" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -58,6 +63,7 @@
expect(client.get_value("testUnknownKey", "default")).to eq "default"
client.stop()
end

it "test_invalidation" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -68,6 +74,7 @@
expect(client.get_value("testBoolKey", false)).to eq true
client.stop()
end

it "test_get_all_keys" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -78,6 +85,25 @@
expect(Set.new(client.get_all_keys())).to eq Set.new(["testBoolKey", "testStringKey", "testIntKey", "testDoubleKey", "key1", "key2"])
client.stop()
end

it "test_get_all_values" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
max_init_wait_time_seconds: 0,
on_configuration_changed_callback: nil,
cache_time_to_live_seconds: 0,
config_cache_class: ConfigCacheMock)
all_values = client.get_all_values()
expect(all_values.size).to eq 6
expect(all_values["testBoolKey"]).to eq true
expect(all_values["testStringKey"]).to eq "testValue"
expect(all_values["testIntKey"]).to eq 1
expect(all_values["testDoubleKey"]).to eq 1.1
expect(all_values["key1"]).to eq true
expect(all_values["key2"]).to eq false
client.stop()
end

it "test_get_variation_id" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -89,6 +115,7 @@
expect(client.get_variation_id("key2", nil)).to eq "fakeId2"
client.stop()
end

it "test_get_variation_id_not_found" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -99,6 +126,7 @@
expect(client.get_variation_id("nonexisting", "default_variation_id")).to eq "default_variation_id"
client.stop()
end

it "test_get_variation_id_empty_config" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -109,6 +137,7 @@
expect(client.get_variation_id("nonexisting", "default_variation_id")).to eq "default_variation_id"
client.stop()
end

it "test_get_all_variation_ids" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand All @@ -122,6 +151,7 @@
expect(result.include?("fakeId2")).to eq true
client.stop()
end

it "test_get_key_and_value" do
client = ConfigCatClient.new("test",
poll_interval_seconds: 0,
Expand Down

0 comments on commit 3af77ba

Please sign in to comment.