-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTestMainModule.lua
79 lines (60 loc) · 1.98 KB
/
TestMainModule.lua
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
-----------
-- test Main module
--- contains VMS general features
-- @module TestMainModule
module("TestMainModule", package.seeall)
local tearDownSteps = {
steps = {},
}
tearDownSteps.add = function(step) table.insert(tearDownSteps.steps, step) end
function suite_setup()
end
function suite_teardown()
end
--- setup function
function setup()
gateway.setHighWaterMark()
end
-----------------------------------------------------------------------------------------------
--- teardown function executed after each unit test
function teardown()
for idx, step in pairs(tearDownSteps.steps) do
step()
end
end
----------------------------------------------------------------------
-- Test Building Blocks
----------------------------------------------------------------------
--- Function breaks VMS service.
-- It renames mail.lua file to mail2.lua to invoke critical error on startup
local function spoilService()
local path = vmsSW:getServicePath()
local inFile = "mail.lua"
local outFile = "mail2.lua"
local result = shellSW:renameFile(path .. inFile, outFile)
tearDownSteps.add(function()
shellSW:renameFile(path .. outFile, inFile)
end)
end
-------------------------
-- Test Cases
-------------------------
--- Tests if VMS disables itself when cricital error occurs
-- 1. spoil VMS by messing in source code
-- 2. Restart framework
-- 3. Check if service was disabled
function test_MainModule_WhenCriticalErrorOnVmsStartup_VmsServiceIsDisabled()
spoilService()
systemSW:restartFramework(true)
tearDownSteps.add(
function()
systemSW:enableService(vmsSW)
systemSW:restartFramework(true)
local vmsInfo = systemSW:getServiceInfo(vmsSW)
assert_equal(vmsInfo.enabled, "True", "Service disabled")
assert_equal(vmsInfo.running, "True", "Service not running")
end
)
local vmsInfo = systemSW:getServiceInfo(vmsSW)
assert_equal(vmsInfo.enabled, "False", "Service running, but critical error should disable it.")
end