File: file_test.rb

package info (click to toggle)
ruby-train 3.13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,208 kB
  • sloc: ruby: 10,002; sh: 17; makefile: 8
file content (129 lines) | stat: -rw-r--r-- 3,232 bytes parent folder | download | duplicates (3)
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
require "helper"

describe Train::File do
  let(:cls) { Train::File }
  let(:new_cls) { cls.new(nil, "/temp/file", false) }

  def mockup(stubs)
    Class.new(cls) do
      stubs.each do |k, v|
        define_method k.to_sym do
          v
        end
      end
    end.new(nil, nil, false)
  end

  it "has the default type of unknown" do
    _(new_cls.type).must_equal :unknown
  end

  it "throws Not implemented error for exist?" do
    # proc { Train.validate_backend({ host: rand }) }.must_raise Train::UserError
    _ { new_cls.exist? }.must_raise NotImplementedError
  end

  it "throws Not implemented error for mode" do
    _ { new_cls.mode }.must_raise NotImplementedError
  end

  it "throws Not implemented error for owner" do
    _ { new_cls.owner }.must_raise NotImplementedError
  end

  it "throws Not implemented error for group" do
    _ { new_cls.group }.must_raise NotImplementedError
  end

  it "throws Not implemented error for uid" do
    _ { new_cls.uid }.must_raise NotImplementedError
  end

  it "throws Not implemented error for gid" do
    _ { new_cls.gid }.must_raise NotImplementedError
  end

  it "throws Not implemented error for content" do
    _ { new_cls.content }.must_raise NotImplementedError
  end

  it "throws Not implemented error for mtime" do
    _ { new_cls.mtime }.must_raise NotImplementedError
  end

  it "throws Not implemented error for size" do
    _ { new_cls.size }.must_raise NotImplementedError
  end

  it "throws Not implemented error for selinux_label" do
    _ { new_cls.selinux_label }.must_raise NotImplementedError
  end

  it "return path of file" do
    _(new_cls.path).must_equal("/temp/file")
  end

  it "set product_version to nil" do
    _(new_cls.product_version).must_be_nil
  end

  it "set product_version to nil" do
    _(new_cls.file_version).must_be_nil
  end

  describe "type" do
    it "recognized type == file" do
      fc = mockup(type: :file)
      _(fc.file?).must_equal true
    end

    it "recognized type == block_device" do
      fc = mockup(type: :block_device)
      _(fc.block_device?).must_equal true
    end

    it "recognized type == character_device" do
      fc = mockup(type: :character_device)
      _(fc.character_device?).must_equal true
    end

    it "recognized type == socket" do
      fc = mockup(type: :socket)
      _(fc.socket?).must_equal true
    end

    it "recognized type == directory" do
      fc = mockup(type: :directory)
      _(fc.directory?).must_equal true
    end

    it "recognized type == pipe" do
      fc = mockup(type: :pipe)
      _(fc.pipe?).must_equal true
    end

    it "recognized type == symlink" do
      fc = mockup(type: :symlink)
      _(fc.symlink?).must_equal true
    end
  end

  describe "version" do
    it "recognized wrong version" do
      fc = mockup(product_version: rand, file_version: rand)
      _(fc.version?(rand)).must_equal false
    end

    it "recognized product_version" do
      x = rand
      fc = mockup(product_version: x, file_version: rand)
      _(fc.version?(x)).must_equal true
    end

    it "recognized file_version" do
      x = rand
      fc = mockup(product_version: rand, file_version: x)
      _(fc.version?(x)).must_equal true
    end
  end
end