Welcome to mirror list, hosted at ThFree Co, Russian Federation.

application_context_tracer_spec.rb « tracers « graphql « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6eff816b95a964c72a62c0abdbbe1cdfa0074b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true
require "fast_spec_helper"
require "support/graphql/fake_tracer"
require "support/graphql/fake_query_type"

RSpec.describe Gitlab::Graphql::Tracers::ApplicationContextTracer do
  let(:tracer_spy) { spy('tracer_spy') }
  let(:default_known_operations) { ::Gitlab::Graphql::KnownOperations.new(['fooOperation']) }
  let(:dummy_schema) do
    schema = Class.new(GraphQL::Schema) do
      use Gitlab::Graphql::Tracers::ApplicationContextTracer

      query Graphql::FakeQueryType
    end

    fake_tracer = Graphql::FakeTracer.new(lambda do |key, *args|
      tracer_spy.trace(key, Gitlab::ApplicationContext.current)
    end)

    schema.tracer(fake_tracer)

    schema
  end

  before do
    allow(::Gitlab::Graphql::KnownOperations).to receive(:default).and_return(default_known_operations)
  end

  it "sets application context during execute_query and cleans up afterwards", :aggregate_failures do
    dummy_schema.execute("query fooOperation { helloWorld }")

    # "parse" is just an arbitrary trace event that isn't setting caller_id
    expect(tracer_spy).to have_received(:trace).with("parse", hash_excluding("meta.caller_id"))
    expect(tracer_spy).to have_received(:trace).with("execute_query", hash_including("meta.caller_id" => "graphql:fooOperation")).once
    expect(Gitlab::ApplicationContext.current).not_to include("meta.caller_id")
  end

  it "sets caller_id when operation is not known" do
    dummy_schema.execute("query fuzz { helloWorld }")

    expect(tracer_spy).to have_received(:trace).with("execute_query", hash_including("meta.caller_id" => "graphql:unknown")).once
  end
end