File: test_path_digest_utils.rb

package info (click to toggle)
ruby-sprockets 3.7.2-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,456 kB
  • sloc: ruby: 10,879; javascript: 73; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 2,611 bytes parent folder | download | duplicates (2)
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
require 'minitest/autorun'
require 'sprockets/path_digest_utils'

class TestPathDigestUtils < Minitest::Test
  include Sprockets::PathDigestUtils

  def test_file_stat_digest
    path = File.expand_path("../fixtures/default/hello.txt", __FILE__)
    assert_equal "81491ac958ab51a3bc7f34cae434cf00c49861402bf6c8961e8ee32afa7c4cf8",
      stat_digest(path, File.stat(path)).unpack("h*")[0]
    assert_equal "81491ac958ab51a3bc7f34cae434cf00c49861402bf6c8961e8ee32afa7c4cf8",
      file_digest(path).unpack("h*")[0]
  end

  def test_directory_stat_digest
    path = File.expand_path("../fixtures/default/app", __FILE__)
    assert_equal "8514e7f087b1666549d97352c8b80925de62e6e27b5a61c3dab780366e2b19a6",
      stat_digest(path, File.stat(path)).unpack("h*")[0]
    assert_equal "8514e7f087b1666549d97352c8b80925de62e6e27b5a61c3dab780366e2b19a6",
      file_digest(path).unpack("h*")[0]
  end

  def test_symlink_stat_digest
    skip "no symlinks available" unless File.symlink?(File.expand_path("../fixtures/default/symlink", __FILE__))

    path = File.expand_path("../fixtures/default/mobile", __FILE__)
    assert_equal "e571f54b8982049817ee30d0bf0dcf5dd8c09252b50696f7ccb44019c9229ccd",
      stat_digest(path, File.stat(path)).unpack("h*")[0]

    path = File.expand_path("../fixtures/default/symlink", __FILE__)
    assert_equal "e571f54b8982049817ee30d0bf0dcf5dd8c09252b50696f7ccb44019c9229ccd",
      stat_digest(path, File.stat(path)).unpack("h*")[0]
    assert_equal "e571f54b8982049817ee30d0bf0dcf5dd8c09252b50696f7ccb44019c9229ccd",
      file_digest(path).unpack("h*")[0]
  end

  def test_unix_device_stat_digest
    if File.exist?("/dev/stdin") && File.stat("/dev/stdin").chardev?
      assert_raises(TypeError) do
        stat_digest("/dev/stdin", File.stat("/dev/stdin"))
      end
      assert_raises(TypeError) do
        file_digest("/dev/stdin")
      end
    else
      skip "no unix device available"
    end
  end

  def test_missing_file_digest
    path = "./filedoesnotexist"
    refute File.exist?(path)
    refute file_digest(path)
  end

  def test_multiple_file_digests
    skip "no symlinks available" unless File.symlink?(File.expand_path("../fixtures/default/symlink", __FILE__))

    paths = []
    paths << File.expand_path("../fixtures/default/hello.txt", __FILE__)
    paths << File.expand_path("../fixtures/default/app", __FILE__)
    paths << File.expand_path("../fixtures/default/symlink", __FILE__)
    paths << "./filedoesnotexist"

    assert_equal "95f41ef27ae30ceaaa726f85b3298e1be4ff4bf5bf83deec0f760b50e3ffc09f",
      files_digest(paths).unpack("h*")[0]
  end
end