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

profile_spec.rb « request_profiler « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e9c75dde87aa9edf665913170ed7b7ef1a4f26f (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::RequestProfiler::Profile do
  let(:profile) { described_class.new(filename) }

  describe '.new' do
    context 'using old filename' do
      let(:filename) { '|api|v4|version.txt_1562854738.html' }

      it 'returns valid data' do
        expect(profile).to be_valid
        expect(profile.request_path).to eq('/api/v4/version.txt')
        expect(profile.time).to eq(Time.at(1562854738).utc)
        expect(profile.type).to eq('html')
      end
    end

    context 'using new filename' do
      let(:filename) { '|api|v4|version.txt_1563547949_execution.html' }

      it 'returns valid data' do
        expect(profile).to be_valid
        expect(profile.request_path).to eq('/api/v4/version.txt')
        expect(profile.profile_mode).to eq('execution')
        expect(profile.time).to eq(Time.at(1563547949).utc)
        expect(profile.type).to eq('html')
      end
    end
  end

  describe '#content_type' do
    context 'when using html file' do
      let(:filename) { '|api|v4|version.txt_1562854738_memory.html' }

      it 'returns valid data' do
        expect(profile).to be_valid
        expect(profile.content_type).to eq('text/html')
      end
    end

    context 'when using text file' do
      let(:filename) { '|api|v4|version.txt_1562854738_memory.txt' }

      it 'returns valid data' do
        expect(profile).to be_valid
        expect(profile.content_type).to eq('text/plain')
      end
    end

    context 'when file is unknown' do
      let(:filename) { '|api|v4|version.txt_1562854738_memory.xxx' }

      it 'returns valid data' do
        expect(profile).not_to be_valid
        expect(profile.content_type).to be_nil
      end
    end
  end
end