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

gitlab_edition_spec.rb « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 46be1471896d189dd85cc5cb8a7a76dd0fd00378 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rspec-parameterized'

RSpec.describe GitlabEdition do
  def remove_instance_variable(ivar)
    described_class.remove_instance_variable(ivar) if described_class.instance_variable_defined?(ivar)
  end

  before do
    # Make sure the ENV is clean
    stub_env('FOSS_ONLY', nil)
    stub_env('EE_ONLY', nil)

    remove_instance_variable(:@is_ee)
    remove_instance_variable(:@is_jh)
  end

  after do
    remove_instance_variable(:@is_ee)
    remove_instance_variable(:@is_jh)
  end

  describe '.root' do
    it 'returns the root path of the app' do
      expect(described_class.root).to eq(Pathname.new(File.expand_path('../..', __dir__)))
    end
  end

  describe '.path_glob' do
    using RSpec::Parameterized::TableSyntax

    let(:root) { described_class.root.to_s }

    subject { described_class.path_glob(path) }

    before do
      allow(described_class).to receive(:jh?).and_return(jh)
      allow(described_class).to receive(:ee?).and_return(ee)
    end

    where(:ee, :jh, :path, :expected) do
      false | false | nil          | ''
      true  | false | nil          | '{,ee/}'
      true  | true  | nil          | '{,ee/,jh/}'
      false | true  | nil          | '{,ee/,jh/}'
      false | false | 'app/models' | 'app/models'
      true  | false | 'app/models' | '{,ee/}app/models'
      true  | true  | 'app/models' | '{,ee/,jh/}app/models'
      false | true  | 'app/models' | '{,ee/,jh/}app/models'
    end

    with_them do
      it { is_expected.to eq("#{root}/#{expected}") }
    end
  end

  describe '.extension_path_prefixes' do
    using RSpec::Parameterized::TableSyntax

    subject { described_class.extension_path_prefixes }

    before do
      allow(described_class).to receive(:jh?).and_return(jh)
      allow(described_class).to receive(:ee?).and_return(ee)
    end

    where(:ee, :jh, :expected) do
      false | false | ''
      true  | false | '{,ee/}'
      true  | true  | '{,ee/,jh/}'
      false | true  | '{,ee/,jh/}'
    end

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

  describe '.extensions' do
    context 'when .jh? is true' do
      before do
        allow(described_class).to receive(:jh?).and_return(true)
      end

      it 'returns %w[ee jh]' do
        expect(described_class.extensions).to match_array(%w[ee jh])
      end
    end

    context 'when .ee? is true' do
      before do
        allow(described_class).to receive(:jh?).and_return(false)
        allow(described_class).to receive(:ee?).and_return(true)
      end

      it 'returns %w[ee]' do
        expect(described_class.extensions).to match_array(%w[ee])
      end
    end

    context 'when neither .jh? and .ee? are true' do
      before do
        allow(described_class).to receive(:jh?).and_return(false)
        allow(described_class).to receive(:ee?).and_return(false)
      end

      it 'returns the extensions according to the current edition' do
        expect(described_class.extensions).to be_empty
      end
    end
  end

  describe '.ee? and .jh?' do
    def stub_path(*paths, **arguments)
      root = Pathname.new('dummy')
      pathname = double(:path, **arguments)

      allow(described_class)
        .to receive(:root)
        .and_return(root)

      allow(root).to receive(:join)

      paths.each do |path|
        allow(root)
          .to receive(:join)
          .with(path)
          .and_return(pathname)
      end
    end

    describe '.ee?' do
      context 'when EE' do
        before do
          stub_path('ee/app/models/license.rb', exist?: true)
        end

        context 'when using FOSS_ONLY=1' do
          before do
            stub_env('FOSS_ONLY', '1')
          end

          it 'returns not to be EE' do
            expect(described_class).not_to be_ee
          end
        end

        context 'when using FOSS_ONLY=0' do
          before do
            stub_env('FOSS_ONLY', '0')
          end

          it 'returns to be EE' do
            expect(described_class).to be_ee
          end
        end

        context 'when using default FOSS_ONLY' do
          it 'returns to be EE' do
            expect(described_class).to be_ee
          end
        end
      end

      context 'when CE' do
        before do
          stub_path('ee/app/models/license.rb', exist?: false)
        end

        it 'returns not to be EE' do
          expect(described_class).not_to be_ee
        end
      end
    end

    describe '.jh?' do
      context 'when JH' do
        before do
          stub_path('ee/app/models/license.rb', 'jh', exist?: true)
        end

        context 'when using default FOSS_ONLY and EE_ONLY' do
          it 'returns to be JH' do
            expect(described_class).to be_jh
          end
        end

        context 'when using FOSS_ONLY=1' do
          before do
            stub_env('FOSS_ONLY', '1')
          end

          it 'returns not to be JH' do
            expect(described_class).not_to be_jh
          end
        end

        context 'when using EE_ONLY=1' do
          before do
            stub_env('EE_ONLY', '1')
          end

          it 'returns not to be JH' do
            expect(described_class).not_to be_jh
          end
        end
      end
    end
  end
end