|
21 | 21 | it "ignores non-boolean results" do |
22 | 22 | scope.add_feature_flag("a", "yes") |
23 | 23 | scope.add_feature_flag("b", nil) |
24 | | - expect(scope.flags).to be_empty |
| 24 | + expect(scope.flags.values).to be_empty |
25 | 25 | end |
26 | 26 |
|
27 | 27 | it "moves a re-evaluated flag to the end with its new result" do |
28 | 28 | scope.add_feature_flag("a", true) |
29 | 29 | scope.add_feature_flag("b", true) |
30 | 30 | scope.add_feature_flag("a", false) |
31 | | - expect(scope.flags).to eq([{ flag: "b", result: true }, { flag: "a", result: false }]) |
| 31 | + expect(scope.flags.values).to eq("b" => true, "a" => false) |
32 | 32 | end |
33 | 33 |
|
34 | 34 | it "evicts the oldest flag beyond the limit" do |
35 | 35 | (Sentry::Scope::MAX_FLAGS + 1).times { |i| scope.add_feature_flag("f#{i}", true) } |
36 | | - expect(scope.flags.size).to eq(Sentry::Scope::MAX_FLAGS) |
37 | | - expect(scope.flags.first[:flag]).to eq("f1") |
| 36 | + expect(scope.flags.values.size).to eq(Sentry::Scope::MAX_FLAGS) |
| 37 | + expect(scope.flags.values.first.first).to eq("f1") |
38 | 38 | end |
39 | 39 |
|
40 | 40 | it "does not add flags to transaction events" do |
|
44 | 44 | expect(event.contexts).not_to have_key(:flags) |
45 | 45 | end |
46 | 46 |
|
| 47 | + it "does not add flags to check-in events" do |
| 48 | + scope.add_feature_flag("a", true) |
| 49 | + event = Sentry::CheckInEvent.new(configuration: Sentry.configuration, slug: "foo", status: :ok) |
| 50 | + scope.apply_to_event(event) |
| 51 | + expect(event.contexts).not_to have_key(:flags) |
| 52 | + end |
| 53 | + |
47 | 54 | it "is isolated in duplicated and updated scopes and cleared by #clear" do |
48 | 55 | scope.add_feature_flag("a", true) |
49 | 56 | copy = scope.dup |
50 | 57 | copy.add_feature_flag("b", true) |
51 | | - copy.flags.first[:result] = false |
52 | | - expect(scope.flags).to eq([{ flag: "a", result: true }]) |
| 58 | + copy.add_feature_flag("a", false) |
| 59 | + expect(scope.flags.values).to eq("a" => true) |
53 | 60 |
|
54 | 61 | updated = described_class.new |
55 | 62 | updated.update_from_scope(scope) |
56 | 63 | updated.add_feature_flag("b", true) |
57 | | - expect(scope.flags).to eq([{ flag: "a", result: true }]) |
| 64 | + expect(scope.flags.values).to eq("a" => true) |
58 | 65 |
|
59 | 66 | scope.clear |
60 | | - expect(scope.flags).to be_empty |
| 67 | + expect(scope.flags.values).to be_empty |
61 | 68 | end |
62 | 69 |
|
63 | 70 | context "with an active span" do |
|
66 | 73 |
|
67 | 74 | it "records flag.evaluation.* span data, capped per span" do |
68 | 75 | scope.add_feature_flag("a", true) |
69 | | - expect(span.data["flag.evaluation.a"]).to eq(true) |
| 76 | + expect(span.to_h[:data]["flag.evaluation.a"]).to eq(true) |
70 | 77 |
|
71 | 78 | 12.times { |i| scope.add_feature_flag("g#{i}", true) } |
72 | | - keys = span.data.keys.select { |k| k.start_with?("flag.evaluation.") } |
73 | | - expect(keys.size).to eq(Sentry::Scope::MAX_FLAGS_PER_SPAN) |
| 79 | + keys = span.to_h[:data].keys.select { |k| k.start_with?("flag.evaluation.") } |
| 80 | + expect(keys.size).to eq(Sentry::Span::MAX_FLAGS) |
74 | 81 |
|
75 | 82 | scope.add_feature_flag("a", false) |
76 | | - expect(span.data["flag.evaluation.a"]).to eq(false) |
| 83 | + expect(span.to_h[:data]["flag.evaluation.a"]).to eq(true) |
77 | 84 | end |
78 | 85 | end |
79 | 86 | end |
80 | 87 |
|
81 | 88 | describe "Sentry.add_feature_flag" do |
82 | 89 | it "adds to the current scope" do |
83 | 90 | Sentry.add_feature_flag("x", true) |
84 | | - expect(Sentry.get_current_scope.flags).to eq([{ flag: "x", result: true }]) |
| 91 | + expect(Sentry.get_current_scope.flags.values).to eq("x" => true) |
85 | 92 | end |
86 | 93 | end |
87 | 94 | end |
0 commit comments