summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/uuid_spec.rb
blob: 44c1d30fce02cfd4d57256d88ec1636c2d6fc053 (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
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::UUID do
  let_it_be(:name) { "GitLab" }

  describe '.v5' do
    subject { described_class.v5(name) }

    before do
      # This is necessary to clear memoization for testing different environments
      described_class.instance_variable_set(:@default_namespace_id, nil)
    end

    context 'in development' do
      let_it_be(:development_proper_uuid) { "5b593e54-90f5-504b-8805-5394a4d14b94" }

      before do
        allow(Rails).to receive(:env).and_return(:development)
      end

      it { is_expected.to eq(development_proper_uuid) }
    end

    context 'in test' do
      let_it_be(:test_proper_uuid) { "5b593e54-90f5-504b-8805-5394a4d14b94" }

      it { is_expected.to eq(test_proper_uuid) }
    end

    context 'in staging' do
      let_it_be(:staging_proper_uuid) { "dd190b37-7754-5c7c-80a0-85621a5823ad" }

      before do
        allow(Rails).to receive(:env).and_return(:staging)
      end

      it { is_expected.to eq(staging_proper_uuid) }
    end

    context 'in production' do
      let_it_be(:production_proper_uuid) { "4961388b-9d8e-5da0-a499-3ef5da58daf0" }

      before do
        allow(Rails).to receive(:env).and_return(:production)
      end

      it { is_expected.to eq(production_proper_uuid) }
    end
  end

  describe 'v5?' do
    using RSpec::Parameterized::TableSyntax

    where(:test_string, :is_uuid_v5) do
      'not even a uuid'                      | false
      'this-seems-like-a-uuid'               | false
      'thislook-more-5lik-eava-liduuidbutno' | false
      '9f470438-db0f-37b7-9ca9-1d47104c339a' | false
      '9f470438-db0f-47b7-9ca9-1d47104c339a' | false
      '9f470438-db0f-57b7-9ca9-1d47104c339a' | true
    end

    with_them do
      subject { described_class.v5?(test_string) }

      it { is_expected.to be(is_uuid_v5) }
    end
  end
end