File: aix_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 (81 lines) | stat: -rw-r--r-- 2,750 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
require "helper"
require "train/transports/local"
require "train/file/remote/aix"
require "train/transports/mock"

describe Train::File::Remote::Aix do
  let(:cls) { Train::File::Remote::Aix }
  let(:backend) do
    backend = Train::Transports::Mock.new.connection
    backend.mock_os({ name: "aix", family: "unix" })
    backend
  end

  it "returns a nil link_path if the object is not a symlink" do
    file = cls.new(backend, "path")
    file.stubs(:symlink?).returns(false)
    _(file.link_path).must_be_nil
  end

  it "returns a correct link_path" do
    file = cls.new(backend, "path")
    file.stubs(:symlink?).returns(true)
    backend.mock_command("perl -e 'print readlink shift' path", "our_link_path")
    _(file.link_path).must_equal "our_link_path"
  end

  it "returns a correct shallow_link_path" do
    file = cls.new(backend, "path")
    file.stubs(:symlink?).returns(true)
    backend.mock_command("perl -e 'print readlink shift' path", "our_link_path")
    _(file.link_path).must_equal "our_link_path"
  end

  describe "#md5sum" do
    let(:md5_checksum) { "57d4c6f9d15313fd5651317e588c035d" }

    let(:ruby_md5_mock) do
      checksum_mock = mock
      checksum_mock.expects(:update).returns("")
      checksum_mock.expects(:hexdigest).returns(md5_checksum)
      checksum_mock
    end

    it "defaults to a Ruby based checksum if other methods fail" do
      backend.mock_command("md5sum /tmp/testfile", "", "", 1)
      Digest::MD5.expects(:new).returns(ruby_md5_mock)
      _(cls.new(backend, "/tmp/testfile").md5sum).must_equal md5_checksum
    end

    it "calculates the correct md5sum on the `aix` platform family" do
      output = "#{md5_checksum} /tmp/testfile"
      backend.mock_command("md5sum /tmp/testfile", output)
      _(cls.new(backend, "/tmp/testfile").md5sum).must_equal md5_checksum
    end
  end

  describe "#sha256sum" do
    let(:sha256_checksum) do
      "491260aaa6638d4a64c714a17828c3d82bad6ca600c9149b3b3350e91bcd283d"
    end

    let(:ruby_sha256_mock) do
      checksum_mock = mock
      checksum_mock.expects(:update).returns("")
      checksum_mock.expects(:hexdigest).returns(sha256_checksum)
      checksum_mock
    end

    it "defaults to a Ruby based checksum if other methods fail" do
      backend.mock_command("sha256sum /tmp/testfile", "", "", 1)
      Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
      _(cls.new(backend, "/tmp/testfile").sha256sum).must_equal sha256_checksum
    end

    it "calculates the correct sha256sum on the `aix` platform family" do
      output = "#{sha256_checksum} /tmp/testfile"
      backend.mock_command("sha256sum /tmp/testfile", output)
      _(cls.new(backend, "/tmp/testfile").sha256sum).must_equal sha256_checksum
    end
  end
end