From 50f8ba2b7594184b6de86165901c8bb9f2d38718 Mon Sep 17 00:00:00 2001 From: Randy Coulman Date: Tue, 9 Jan 2024 21:45:55 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Use=20capture=5Flog=20instead=20of?= =?UTF-8?q?=20with=5Flog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit with_log wasn't introduced until Elixir 1.13, but we still run CI on 1.12. --- test/config_cat_test.exs | 8 +++----- test/evaluation_log_test.exs | 7 +++---- test/rollout_test.exs | 32 +++++++++++++------------------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/test/config_cat_test.exs b/test/config_cat_test.exs index f184de04..6e98b3a5 100644 --- a/test/config_cat_test.exs +++ b/test/config_cat_test.exs @@ -175,13 +175,11 @@ defmodule ConfigCatTest do warning? = unquote(warning?) user = if user_id, do: User.new(user_id) - {value, logs} = - with_log(fn -> - ConfigCat.get_value(key, default_value, user, client: client) + logs = + capture_log(fn -> + assert expected_value == ConfigCat.get_value(key, default_value, user, client: client) end) - assert value == expected_value - if warning? do default_type = SettingType.infer_elixir_type(default_value) expected_type = SettingType.infer_elixir_type(expected_value) diff --git a/test/evaluation_log_test.exs b/test/evaluation_log_test.exs index 58720995..5b6eecc0 100644 --- a/test/evaluation_log_test.exs +++ b/test/evaluation_log_test.exs @@ -108,9 +108,9 @@ defmodule ConfigCat.EvaluationLogTest do # test_name = Path.basename(expected_log_file, ".txt") expected_log = File.read!(Path.join(suite_sub_dir, expected_log_file)) - {value, log} = - with_log(fn -> - ConfigCat.get_value(key, default_value, user, client: client) + log = + capture_log(fn -> + assert return_value == ConfigCat.get_value(key, default_value, user, client: client) end) {expected_clean_log, expected_user} = extract_logged_user(expected_log) @@ -118,7 +118,6 @@ defmodule ConfigCat.EvaluationLogTest do assert clean_log == expected_clean_log assert actual_user == expected_user - assert value == return_value end defp build_user(nil), do: nil diff --git a/test/rollout_test.exs b/test/rollout_test.exs index 90ed0d7f..fe1e15d5 100644 --- a/test/rollout_test.exs +++ b/test/rollout_test.exs @@ -172,13 +172,11 @@ defmodule ConfigCat.RolloutTest do key = "boolTextEqualsNumber" - {value, logs} = - with_log(fn -> - ConfigCat.get_value(key, nil, user, client: client) + logs = + capture_log(fn -> + assert ConfigCat.get_value(key, nil, user, client: client) end) - assert value - expected_log = "warning [3005] Evaluation of condition (User.#{custom_attribute_name} EQUALS '#{custom_attribute_value}') " <> "for setting '#{key}' may not produce the expected result (the User.#{custom_attribute_name} attribute is not a string value, " <> @@ -201,13 +199,11 @@ defmodule ConfigCat.RolloutTest do } """) - {details, logs} = - with_log(fn -> - Rollout.evaluate("test", nil, false, "default_variation_id", config) + logs = + capture_log(fn -> + assert %EvaluationDetails{value: false} = Rollout.evaluate("test", nil, false, "default_variation_id", config) end) - assert %EvaluationDetails{value: false} = details - expected_log = "error [2001] Failed to evaluate setting 'test'. " <> "(Setting value is not of the expected type String.t())" @@ -325,12 +321,12 @@ defmodule ConfigCat.RolloutTest do |> LocalFileDataSource.new(:local_only) |> OverrideDataSource.overrides() - {details, logs} = - with_log(fn -> - Rollout.evaluate(key, nil, "default_value", "default_variation_id", config) + logs = + capture_log(fn -> + assert %EvaluationDetails{value: "default_value"} = + Rollout.evaluate(key, nil, "default_value", "default_variation_id", config) end) - assert %EvaluationDetails{value: "default_value"} = details assert logs =~ "Circular dependency detected" assert logs =~ dependency_cycle end @@ -378,13 +374,11 @@ defmodule ConfigCat.RolloutTest do {:ok, client} = start_config_cat(sdk_key, flag_overrides: flag_overrides) - {value, logs} = - with_log(fn -> - ConfigCat.get_value(key, nil, client: client) + logs = + capture_log(fn -> + assert expected_value == ConfigCat.get_value(key, nil, client: client) end) - assert value == expected_value - unless expected_value do flag_value_type = SettingType.infer_elixir_type(flag_value)