-
Notifications
You must be signed in to change notification settings - Fork 12
/
service_spec.cr
99 lines (83 loc) · 2.36 KB
/
service_spec.cr
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
require "./spec_helper"
require "../src/service"
require "../src/prefix"
require "file_utils"
module Service
def self.init=(@@init)
@@initialized = true
end
module InitSystem
def file=(@file)
end
end
class Systemd
def self.version=(@@version)
end
# systemctl may not exist
private def daemon_reload
end
end
end
struct DPPM::Prefix::App
def service=(@service)
end
end
def spec_with_service_app(service, &block)
spec_with_tempdir do |path|
test_prefix = DPPM::Prefix.new path
test_prefix.create
test_prefix.ensure_app_dir
test_app = test_prefix.new_app(TEST_APP_PACKAGE_NAME)
FileUtils.cp_r Path[SAMPLES_DIR, TEST_APP_PACKAGE_NAME].to_s, test_app.path.to_s
test_app.service = service.new test_app.name
test_app.service.file = test_app.service_path / "test_service"
test_app.service_create.config
yield test_app
end
end
def assert_service(service, file = __FILE__, line = __LINE__)
spec_with_service_app service do |app|
it "creates a service config", file, line do
config = app.service.config
config.user.should be_a String
config.group.should be_a String
config.directory.should be_a String
config.command.should be_a String
config.reload_signal.should be_a String
config.description.should be_a String
config.log_output.should be_a String
end
it "parses the service", file, line do
app.service.config
end
it "gets user value", file, line do
app.service.config.user.should eq app.owner.user.name
end
it "verifies PATH environment variable", file, line do
app.service.config.env_vars["PATH"].should eq app.path_env_var
end
end
it "creates a service file building", file, line do
spec_with_service_app service do |app|
service_config = String.build do |str|
app.service.config.build str
end
File.read(app.service_file).should eq service_config
end
end
end
describe Service do
describe Service::OpenRC do
assert_service Service::OpenRC
end
describe Service::Systemd do
describe "version < 236 with file logging workaround" do
Service::Systemd.version = 230
assert_service Service::Systemd
end
describe "recent version supporting file logging" do
Service::Systemd.version = 240
assert_service Service::Systemd
end
end
end