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

environment_spec.rb « slug « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e23ad118d442414ca5946c34c34c8506f7a301a (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
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rspec-parameterized'

RSpec.describe Gitlab::Slug::Environment, feature_category: :environment_management do
  describe '#generate' do
    using RSpec::Parameterized::TableSyntax

    subject { described_class.new(name).generate }

    before do
      # ('a' * 64).to_i(16).to_s(36).last(6) gives 'q517sa'
      allow(Digest::SHA2).to receive(:hexdigest).with(name.to_s).and_return('a' * 64)
    end

    where(:name, :slug) do
      "staging-12345678901234567" | "staging-123456789-q517sa"
      "9-staging-123456789012345" | "env-9-staging-123-q517sa"
      "staging-1234567890123456"  | "staging-1234567890123456"
      "staging-1234567890123456-" | "staging-123456789-q517sa"
      "production"                | "production"
      "PRODUCTION"                | "production-q517sa"
      "review/1-foo"              | "review-1-foo-q517sa"
      "1-foo"                     | "env-1-foo-q517sa"
      "1/foo"                     | "env-1-foo-q517sa"
      "foo-"                      | "foo"
      "foo--bar"                  | "foo-bar-q517sa"
      "foo**bar"                  | "foo-bar-q517sa"
      "*-foo"                     | "env-foo-q517sa"
      "staging-12345678-"         | "staging-12345678"
      "staging-12345678-01234567" | "staging-12345678-q517sa"
      ""                          | "env-q517sa"
      nil                         | "env-q517sa"
    end

    with_them do
      it { is_expected.to eq(slug) }
    end
  end
end