Merge branch '8784-dir-listings'
[arvados.git] / services / api / test / unit / app_version_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class AppVersionTest < ActiveSupport::TestCase
8
9   setup do AppVersion.forget end
10
11   teardown do AppVersion.forget end
12
13   test 'invoke git processes only on first call' do
14     AppVersion.expects(:git).
15       with("status", "--porcelain").once.
16       yields " M services/api/README\n"
17     AppVersion.expects(:git).
18       with("log", "-n1", "--format=%H").once.
19       yields "da39a3ee5e6b4b0d3255bfef95601890afd80709\n"
20
21     (0..4).each do
22       v = AppVersion.hash
23       assert_equal 'da39a3ee-modified', v
24     end
25   end
26
27   test 'override with configuration "foobar"' do
28     Rails.configuration.source_version = 'foobar'
29     assert_equal 'foobar', AppVersion.hash
30   end
31
32   test 'override with configuration false' do
33     Rails.configuration.source_version = false
34     assert_not_equal 'foobar', AppVersion.hash
35   end
36
37   test 'override with file' do
38     path = Rails.root.join 'git-commit.version'
39     assert(!File.exist?(path),
40            "Packaged version file found in source tree: #{path}")
41     begin
42       File.open(path, 'w') do |f|
43         f.write "0.1.abc123\n"
44       end
45       assert_equal "0.1.abc123", AppVersion.hash
46     ensure
47       File.unlink path
48     end
49   end
50 end