summaryrefslogtreecommitdiff
path: root/spec/unit/plugins/linux/systemd_paths_spec.rb
blob: 04bf4adededfb1bf3fe5dd7ed259c56138919143 (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
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
#
# Author:: Davide Cavalca <dcavalca@fb.com>
# Copyright:: Copyright (c) 2017 Facebook
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS"BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")

describe Ohai::System, "Linux systemd paths plugin" do
  let(:plugin) { get_plugin("linux/systemd_paths") }

  before do
    allow(plugin).to receive(:collect_os).and_return(:linux)
  end

  it "populates systemd_paths if systemd-path is found" do
    systemd_path_out = <<~SYSTEMD_PATH_OUT
      temporary: /tmp
      temporary-large: /var/tmp
      system-binaries: /usr/bin
      system-include: /usr/include
      system-library-private: /usr/lib
      system-library-arch: /usr/lib/x86_64-linux-gnu
      system-shared: /usr/share
      system-configuration-factory: /usr/share/factory/etc
      system-state-factory: /usr/share/factory/var
      system-configuration: /etc
      system-runtime: /run
      system-runtime-logs: /run/log
      system-state-private: /var/lib
      system-state-logs: /var/log
      system-state-cache: /var/cache
      system-state-spool: /var/spool
      user-binaries: /home/foo/.local/bin
      user-library-private: /home/foo/.local/lib
      user-library-arch: /home/foo/.local/lib/x86_64-linux-gnu
      user-shared: /home/foo/.local/share
      user-configuration: /home/foo/.config
      user-runtime: /run/user/1000
      user-state-cache: /home/foo/.cache
      user: /home/foo
      user-documents: /home/foo/Documents
      user-music: /home/foo/Music
      user-pictures: /home/foo/Pictures
      user-videos: /home/foo/Videos
      user-download: /home/foo/Downloads
      user-public: /home/foo/Public
      user-templates: /home/foo/Templates
      user-desktop: /home/foo/Desktop
      search-binaries: /home/foo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/facebook/bin:/home/foo/.rvm/bin:/home/foo/.rvm/bin
      search-library-private: /home/foo/.local/lib:/usr/local/lib:/usr/lib:/lib
      search-library-arch: /home/foo/.local/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu
      search-shared: /home/foo/.local/share:/usr/share/gnome:/home/foo/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
      search-configuration-factory: /usr/local/share/factory/etc:/usr/share/factory/etc
      search-state-factory: /usr/local/share/factory/var:/usr/share/factory/var
      search-configuration: /home/foo/.config:/etc
    SYSTEMD_PATH_OUT

    allow(plugin).to receive(:which).with("systemd-path").and_return("/bin/systemd-path")
    allow(plugin).to receive(:shell_out).with("/bin/systemd-path").and_return(mock_shell_out(0, systemd_path_out, ""))
    plugin.run
    expect(plugin[:systemd_paths].to_hash).to eq({
      "search-binaries" => "/home/foo/bin",
      "search-configuration" => "/home/foo/.config",
      "search-configuration-factory" => "/usr/local/share/factory/etc",
      "search-library-arch" => "/home/foo/.local/lib/x86_64-linux-gnu",
      "search-library-private" => "/home/foo/.local/lib",
      "search-shared" => "/home/foo/.local/share",
      "search-state-factory" => "/usr/local/share/factory/var",
      "system-binaries" => "/usr/bin",
      "system-configuration" => "/etc",
      "system-configuration-factory" => "/usr/share/factory/etc",
      "system-include" => "/usr/include",
      "system-library-arch" => "/usr/lib/x86_64-linux-gnu",
      "system-library-private" => "/usr/lib",
      "system-runtime" => "/run",
      "system-runtime-logs" => "/run/log",
      "system-shared" => "/usr/share",
      "system-state-cache" => "/var/cache",
      "system-state-factory" => "/usr/share/factory/var",
      "system-state-logs" => "/var/log",
      "system-state-private" => "/var/lib",
      "system-state-spool" => "/var/spool",
      "temporary" => "/tmp",
      "temporary-large" => "/var/tmp",
      "user" => "/home/foo",
      "user-binaries" => "/home/foo/.local/bin",
      "user-configuration" => "/home/foo/.config",
      "user-desktop" => "/home/foo/Desktop",
      "user-documents" => "/home/foo/Documents",
      "user-download" => "/home/foo/Downloads",
      "user-library-arch" => "/home/foo/.local/lib/x86_64-linux-gnu",
      "user-library-private" => "/home/foo/.local/lib",
      "user-music" => "/home/foo/Music",
      "user-pictures" => "/home/foo/Pictures",
      "user-public" => "/home/foo/Public",
      "user-runtime" => "/run/user/1000",
      "user-shared" => "/home/foo/.local/share",
      "user-state-cache" => "/home/foo/.cache",
      "user-templates" => "/home/foo/Templates",
      "user-videos" => "/home/foo/Videos",
    })
  end

  it "does not populate systemd paths if systemd-path is not found" do
    allow(plugin).to receive(:which).with("systemd-path").and_return(false)
    plugin.run
    expect(plugin[:systemd_paths]).to be(nil)
  end
end