Module: Check
Overview
校验相关服务的顶层接口e.g. log/data/env…
- Author
-
chenjie
- Data
-
2009-4-30
建议使用的ruby assert库子集
Asserts that boolean is not false or nil. Example:
assert [1, 2].include?(5)
assert(boolean, =nil)
Passes if expected == +actual. Note that the ordering of arguments is important, since a helpful error message is generated when this one fails that tells you the values of expected and actual. Example:
assert_equal 'MY STRING', 'my string'.upcase
assert_equal(expected, actual, =nil)
Passes if string =~ pattern. Example:
assert_match(/\d+/, 'five, 6, seven')
assert_match(pattern, string, ="")
Passes if object is nil. Example:
assert_nil [1, 2].uniq!
assert_nil(object, ="")
Passes if expected != actual Example:
assert_not_equal 'some string', 5
assert_not_equal(expected, actual, ="")
Passes if ! object .nil? Example:
assert_not_nil '1 two 3'.sub!(/two/, '2')
assert_not_nil(object, ="")
Flunk always fails. Example:
flunk 'Not done testing yet.'
flunk(="Flunked")
Instance Method Summary collapse
-
#_assert_log_match(log_level, pattern, msg = "") ⇒ Object
功能 验证最新的日志内容中匹配到关键字 简化版方法,减少参数传递 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量 ===example _assert_log_match [“DEBUG”], “time”.
-
#_assert_log_match_times(log_level, pattern, n, msg = "") ⇒ Object
功能 验证最新的日志中匹配到关键字的次数 简化版方法,减少参数传递 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量 === example: _assert_log_match_times [“DEBUG”], “time”, 2.
-
#_assert_no_log ⇒ Object
功能 验证没有新日志 简化版方法,减少参数传递 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量 ===example _assert_no_log.
-
#_assert_no_wflog ⇒ Object
功能 验证没有新异常日志 简化版方法,减少参数传递 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量 === example _assert_no_wflog.
-
#_assert_wflog_match(log_level, pattern, msg = "") ⇒ Object
功能 验证最新的异常日志中匹配到关键字 简化版方法,减少参数传递 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量 ===example _assert_wflog_match [“DEBUG”], “time”.
-
#_assert_wflog_match_times(log_level, pattern, n, msg = "") ⇒ Object
功能 验证最新的异常日志中匹配到关键字的次数 简化版方法,减少参数传递 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量 === example: _assert_wflog_match_times [“DEBUG”], “time”, 2.
-
#assert_content(file1, file2, msg = "") ⇒ Object
功能: 验证两个本地文件中的content字段的内容相同 === Example: assert_content “a.txt”, “b.txt”.
-
#assert_file_exist?(host, file_path, msg = "", user = USERNAME, password = PASSWORD) ⇒ Boolean
Example: assert_content “a.txt”, “b.txt”.
-
#assert_file_include_by_str(file1, file2, msg = "") ⇒ Object
功能 验证file1中的内容是否被file2所包含 比较时忽略不可见字符 ===example assert_file_include_by_str file1, file2.
-
#assert_file_match(file, pattern, msg = "") ⇒ Object
功能 验证文件内容匹配pattern ===example assert_file_match file1, “time”.
-
#assert_file_match_times(file, pattern, n, msg = "") ⇒ Object
功能 验证文件内容匹配pattern n次 ===example assert_file_match_times file1, “time”, 3.
-
#assert_file_md5(file1, file2, msg = "") ⇒ Object
功能 验证两个本地文件的md5相同 === example assert_file_md5 “/home/space/space/data/file1”, “/home/space/space/data/file2”.
-
#assert_file_not_same(file1, file2, msg = "") ⇒ Object
功能 验证两个本地文件的内容不同 ===example assert_file_not_same file1, file2.
-
#assert_file_same(file1, file2, msg = "") ⇒ Object
功能 验证两个本地文件的内容相同 ===example assert_file_same file1, file2.
-
#assert_file_same_by_str(file1, file2, msg = "") ⇒ Object
功能 验证两个本地文件的内容相同,比较文本 比较时忽略不可见字符 ===example assert_file_same_by_str file1, file2.
-
#assert_head_value(head_file, key, expect_value, msg = "") ⇒ Object
功能 验证(res)nshead文件对应key值的value是否符合预期 ===参数 - head_file - key - expect_value ===example assert_head_value file1, logid, 3423432 author: chenjie date: 2009-7-9.
-
#assert_include(short, long, msg) ⇒ Object
功能 验证short是否被long所包含 比较时忽略不可见字符 ===example assert_include shortstring, longstring, “”.
-
#assert_log_match(host, log_path, log_name, log_level, pattern, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能 验证最新日志中是否匹配到关键字 ===参数 - host - log_path - log_name - log_level 日志级别数字,可以包含如下枚举值[“DEBUG”, “NOTICE”, “WARNING”, “FATAL”] - pattern - msg pass if the newly log content match the pattern; fail if not ===exmaple assert_log_match host, path, “log1”, [“DEBUG”, “WARNING”], “time”.
-
#assert_log_match_times(host, log_path, log_name, log_level, pattern, n, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能: 验证最新的日志内容中匹配到关键字 ===参数 - host - log_path - log_name - log_level 日志级别数字,可以包含如下枚举值[“DEBUG”, “NOTICE”, “WARNING”, “FATAL”] - pattern - n expected match times - msg pass if the newly log content match the pattern n times; fail if not Example: assert_log_match_times host, “/home/space/space/log/”, “log1”, [“DEBUG”], “time”, 2.
-
#assert_no_log(host, log_path, log_name, user = USERNAME, password = PASSWORD) ⇒ Object
功能 验证没有新日志 ===example assert_no_log host, path, “log1”.
-
#assert_process_not_running(host, module_name, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能 验证进程没有启动 === example assert_process_not_running host, “friend”.
-
#assert_process_running(host, module_name, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能 验证进程启动 === example assert_process_running host, “friend”.
-
#assert_process_threads(host, module_name, n, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能 验证进程启动线程数 ===example assert_process_threads host, “friend”, 3.
Methods included from DATA
#_init_file_, #file_exist?, #file_match?, #file_match_times, #file_size?, #get_all_pack, #get_mcpack_value, #include_file_str, #same_content_value, #same_file_contents, #same_file_md5, #same_file_str
Methods included from Log
#_monitor_log, #_monitor_wflog, #get_match_lines, #get_match_times, #get_match_value, #get_match_values, #has_new_log?, #monitor_log
Instance Method Details
#_assert_log_match(log_level, pattern, msg = "") ⇒ Object
功能
验证最新的日志内容中匹配到关键字简化版方法,减少参数传递约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
example
_assert_log_match [“DEBUG”], “time”
129 130 131 |
# File 'lib/common/socket/check.rb', line 129 def _assert_log_match log_level, pattern, msg="" assert_log_match IP, LOG_PATH, LOG, log_level, pattern, msg end |
#_assert_log_match_times(log_level, pattern, n, msg = "") ⇒ Object
功能
验证最新的日志中匹配到关键字的次数简化版方法,减少参数传递约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
example:
_assert_log_match_times [“DEBUG”], “time”, 2
90 91 92 |
# File 'lib/common/socket/check.rb', line 90 def _assert_log_match_times log_level, pattern, n, msg="" assert_log_match_times IP, LOG_PATH, LOG, log_level, pattern, n, msg end |
#_assert_no_log ⇒ Object
功能
验证没有新日志简化版方法,减少参数传递约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
example
_assert_no_log
158 159 160 |
# File 'lib/common/socket/check.rb', line 158 def _assert_no_log assert_no_log IP, LOG_PATH, LOG end |
#_assert_no_wflog ⇒ Object
功能
验证没有新异常日志简化版方法,减少参数传递约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
example
_assert_no_wflog
168 169 170 |
# File 'lib/common/socket/check.rb', line 168 def _assert_no_wflog assert_no_log IP, LOG_PATH, WFLOG end |
#_assert_wflog_match(log_level, pattern, msg = "") ⇒ Object
功能
验证最新的异常日志中匹配到关键字简化版方法,减少参数传递约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
example
_assert_wflog_match [“DEBUG”], “time”
139 140 141 |
# File 'lib/common/socket/check.rb', line 139 def _assert_wflog_match log_level, pattern, msg="" assert_log_match IP, LOG_PATH, WFLOG, log_level, pattern, msg end |
#_assert_wflog_match_times(log_level, pattern, n, msg = "") ⇒ Object
功能
验证最新的异常日志中匹配到关键字的次数简化版方法,减少参数传递约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
example:
_assert_wflog_match_times [“DEBUG”], “time”, 2
100 101 102 |
# File 'lib/common/socket/check.rb', line 100 def _assert_wflog_match_times log_level, pattern, n, msg="" assert_log_match_times IP, LOG_PATH, WFLOG, log_level, pattern, n, msg end |
#assert_content(file1, file2, msg = "") ⇒ Object
功能:
验证两个本地文件中的content字段的内容相同
Example:
assert_content “a.txt”, “b.txt”
199 200 201 202 203 |
# File 'lib/common/socket/check.rb', line 199 def assert_content file1, file2, msg="" $log.debug "assert content same: file1 = #{file1}, file2 = #{file2}" assert(same_content_value(file1, file2), msg) $log.info "assert content same success, #{file1}, #{file2}" end |
#assert_file_exist?(host, file_path, msg = "", user = USERNAME, password = PASSWORD) ⇒ Boolean
Example:
assert_content “a.txt”, “b.txt”
276 277 278 279 |
# File 'lib/common/socket/check.rb', line 276 def assert_file_exist? host, file_path, msg="", user=USERNAME, password=PASSWORD puts "assert_file_exist? host=#{host}, file_path=#{file_path}" assert(file_exist?(host, file_path, user, password), msg ) end |
#assert_file_include_by_str(file1, file2, msg = "") ⇒ Object
功能
验证file1中的内容是否被file2所包含比较时忽略不可见字符
example
assert_file_include_by_str file1, file2
221 222 223 224 225 |
# File 'lib/common/socket/check.rb', line 221 def assert_file_include_by_str file1, file2, msg="" $log.debug "assert file same by string: file1 = #{file1}, file2 = #{file2}" assert(include_file_str(file1, file2), msg) $log.info "assert file same by string success, #{file1}, #{file2}" end |
#assert_file_match(file, pattern, msg = "") ⇒ Object
功能
验证文件内容匹配pattern
example
assert_file_match file1, “time”
257 258 259 260 |
# File 'lib/common/socket/check.rb', line 257 def assert_file_match file, pattern, msg="" assert(file_match?(file, pattern), msg) $log.info "assert file match success, #{file}, #{pattern}" end |
#assert_file_match_times(file, pattern, n, msg = "") ⇒ Object
功能
验证文件内容匹配pattern n次
example
assert_file_match_times file1, “time”, 3
266 267 268 269 270 |
# File 'lib/common/socket/check.rb', line 266 def assert_file_match_times file, pattern, n, msg="" $log.debug "assert file=#{file}, pattern=#{pattern} " assert_equal(n, file_match_times(file, pattern), msg) $log.info "assert file match times success, #{file}, pattern=#{pattern}, n=#{n}" end |
#assert_file_md5(file1, file2, msg = "") ⇒ Object
功能
验证两个本地文件的md5相同
example
assert_file_md5 “/home/space/space/data/file1”, “/home/space/space/data/file2”
180 181 182 183 |
# File 'lib/common/socket/check.rb', line 180 def assert_file_md5 file1, file2, msg="" assert(same_file_md5(file1, file2), msg) $log.info "assert file md5 success, #{file1}, #{file2}" end |
#assert_file_not_same(file1, file2, msg = "") ⇒ Object
功能
验证两个本地文件的内容不同
example
assert_file_not_same file1, file2
248 249 250 251 |
# File 'lib/common/socket/check.rb', line 248 def assert_file_not_same file1, file2, msg="" assert(!same_file_contents(file1, file2), msg) $log.info "assert file not same success, #{file1}, #{file2}" end |
#assert_file_same(file1, file2, msg = "") ⇒ Object
功能
验证两个本地文件的内容相同
example
assert_file_same file1, file2
189 190 191 192 193 |
# File 'lib/common/socket/check.rb', line 189 def assert_file_same file1, file2, msg="" $log.debug "assert file same: file1 = #{file1}, file2 = #{file2}" assert(same_file_contents(file1, file2), msg) $log.info "assert file same success, #{file1}, #{file2}" end |
#assert_file_same_by_str(file1, file2, msg = "") ⇒ Object
功能
验证两个本地文件的内容相同,比较文本比较时忽略不可见字符
example
assert_file_same_by_str file1, file2
210 211 212 213 214 |
# File 'lib/common/socket/check.rb', line 210 def assert_file_same_by_str file1, file2, msg="" $log.debug "assert file same by string: file1 = #{file1}, file2 = #{file2}" assert(same_file_str(file1, file2), msg) $log.info "assert file same by string success, #{file1}, #{file2}" end |
#assert_head_value(head_file, key, expect_value, msg = "") ⇒ Object
功能
验证(res)nshead文件对应key值的value是否符合预期
参数
-
head_file
-
key
-
expect_value
example
assert_head_value file1, logid, 3423432 author: chenjie date: 2009-7-9
237 238 239 240 241 242 |
# File 'lib/common/socket/check.rb', line 237 def assert_head_value head_file, key, expect_value, msg="" $log.debug "assert head value: head_file = #{head_file}, key = #{key}, expect_value = #{expect_value}" value = get_conf '127.0.0.1', head_file, key assert_equal expect_value, value, msg $log.debug "assert head value success, head_file = #{head_file}, key = #{key}, expect_value = #{expect_value}" end |
#assert_include(short, long, msg) ⇒ Object
功能
验证short是否被long所包含比较时忽略不可见字符
example
assert_include shortstring, longstring, “”
286 287 288 289 |
# File 'lib/common/socket/check.rb', line 286 def assert_include short, long, msg minclude = long.strip.chomp.scan(short.strip.chomp) assert(minclude.size>0, msg) end |
#assert_log_match(host, log_path, log_name, log_level, pattern, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能
验证最新日志中是否匹配到关键字
参数
-
host
-
log_path
-
log_name
-
log_level 日志级别数字,可以包含如下枚举值[“DEBUG”, “NOTICE”, “WARNING”, “FATAL”]
-
pattern
-
msg
pass if the newly log content match the pattern; fail if not
exmaple
assert_log_match host, path, “log1”, [“DEBUG”, “WARNING”], “time”
117 118 119 120 121 |
# File 'lib/common/socket/check.rb', line 117 def assert_log_match host, log_path, log_name, log_level, pattern, msg="", user=USERNAME, password=PASSWORD $log.info "assert log match, logfile=#{host}:#{log_path}:#{log_name}, #{log_level}, #{pattern}" assert(get_match_times(host, log_path, log_name, log_level, pattern, user, password) > 0) $log.info "assert log match success" end |
#assert_log_match_times(host, log_path, log_name, log_level, pattern, n, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能:
验证最新的日志内容中匹配到关键字
参数
-
host
-
log_path
-
log_name
-
log_level 日志级别数字,可以包含如下枚举值[“DEBUG”, “NOTICE”, “WARNING”, “FATAL”]
-
pattern
-
n expected match times
-
msg
pass if the newly log content match the pattern n times; fail if not Example: assert_log_match_times host, “/home/space/space/log/”, “log1”, [“DEBUG”], “time”, 2
77 78 79 80 81 82 |
# File 'lib/common/socket/check.rb', line 77 def assert_log_match_times host, log_path, log_name, log_level, pattern, n, msg="", user=USERNAME, password=PASSWORD match_times = get_match_times(host, log_path, log_name, log_level, pattern, user, password) $log.debug "match times = #{match_times}" assert_equal n, match_times, msg $log.info "assert log match times success, logfile=#{host}:#{log_path}:#{log_name}, #{log_level}, pattern=#{pattern}, n=#{n}" end |
#assert_no_log(host, log_path, log_name, user = USERNAME, password = PASSWORD) ⇒ Object
功能
验证没有新日志
example
assert_no_log host, path, “log1”
147 148 149 150 |
# File 'lib/common/socket/check.rb', line 147 def assert_no_log host, log_path, log_name, user=USERNAME, password=PASSWORD assert(!has_new_log?(host, log_path, log_name, user, password)) $log.info "assert no log success, logfile=#{host}:#{log_path}:#{log_name}" end |
#assert_process_not_running(host, module_name, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能
验证进程没有启动
example
assert_process_not_running host, “friend”
308 309 310 311 |
# File 'lib/common/socket/check.rb', line 308 def assert_process_not_running host, module_name, msg="", user=USERNAME, password=PASSWORD assert(!is_process_running?(host, module_name, user, password), msg) $log.info "assert process not running success, host=#{host}, module=#{module_name}" end |
#assert_process_running(host, module_name, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能
验证进程启动
example
assert_process_running host, “friend”
299 300 301 302 |
# File 'lib/common/socket/check.rb', line 299 def assert_process_running host, module_name, msg="", user=USERNAME, password=PASSWORD assert(is_process_running?(host, module_name, user, password), msg) $log.info "assert process running success, host=#{host}, module=#{module_name}" end |
#assert_process_threads(host, module_name, n, msg = "", user = USERNAME, password = PASSWORD) ⇒ Object
功能
验证进程启动线程数
example
assert_process_threads host, “friend”, 3
317 318 319 320 |
# File 'lib/common/socket/check.rb', line 317 def assert_process_threads host, module_name,n, msg="", user=USERNAME, password=PASSWORD assert_equal(n, get_thread_num(host, module_name, user, password), msg) $log.info "assert process threads success, host=#{host}, module=#{module_name}, n=#{n}" end |