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

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

require "spec_helper"

RSpec.describe StorageHelper do
  describe "#storage_counter" do
    it "formats bytes to one decimal place" do
      expect(helper.storage_counter(1.23.megabytes)).to eq("1.2 MiB")
    end

    it "does not add decimals for sizes < 1 MiB" do
      expect(helper.storage_counter(23.5.kilobytes)).to eq("24 KiB")
    end

    it "does not add decimals for zeroes" do
      expect(helper.storage_counter(2.megabytes)).to eq("2 MiB")
    end

    it "uses commas as thousands separator" do
      expect(helper.storage_counter(100_000_000_000_000_000_000_000)).to eq("86,736.2 EiB")
    end
  end

  describe "#storage_counters_details" do
    let_it_be(:namespace) { create(:namespace) }
    let_it_be(:project) do
      create(
        :project,
        namespace: namespace,
        statistics: build(
          :project_statistics,
          namespace: namespace,
          repository_size: 10.kilobytes,
          wiki_size: 10.bytes,
          lfs_objects_size: 20.gigabytes,
          build_artifacts_size: 30.megabytes,
          pipeline_artifacts_size: 11.megabytes,
          snippets_size: 40.megabytes,
          packages_size: 12.megabytes,
          uploads_size: 15.megabytes
        )
      )
    end

    let(:message) do
      'Repository: 10 KiB / Wikis: 10 B / Build Artifacts: 30 MiB / Pipeline Artifacts: 11 MiB / ' \
        'LFS: 20 GiB / Snippets: 40 MiB / Packages: 12 MiB / Uploads: 15 MiB'
    end

    it 'works on ProjectStatistics' do
      expect(helper.storage_counters_details(project.statistics)).to eq(message)
    end

    it 'works on Namespace.with_statistics' do
      namespace_stats = Namespace.with_statistics.find(project.namespace.id)

      expect(helper.storage_counters_details(namespace_stats)).to eq(message)
    end
  end
end