Skip to content

Commit

Permalink
Fix registrar test for Solaris.
Browse files Browse the repository at this point in the history
And generally change the test to provide more verbose errors on failure.
  • Loading branch information
andrewkroh committed Mar 29, 2016
1 parent d38d27d commit f9e2490
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions filebeat/tests/system/test_registrar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from filebeat import BaseTest

import os
import platform


# Additional tests: to be implemented
# * Check if registrar file can be configured, set config param
Expand All @@ -20,16 +22,16 @@ def test_registrar_file_content(self):
)
os.mkdir(self.working_dir + "/log/")

# Use \n as line terminator on all platforms per docs.
line = "hello world\n"
line_len = len(line) - 1 + len(os.linesep)
iterations = 5
testfile = self.working_dir + "/log/test.log"
file = open(testfile, 'w')

iterations = 5
file.write(iterations * "hello world\n")

file.write(iterations * line)
file.close()

filebeat = self.start_beat()

self.wait_until(
lambda: self.log_contains(
"Processing 5 events"),
Expand All @@ -43,42 +45,37 @@ def test_registrar_file_content(self):
max_timeout=1)
filebeat.check_kill_and_wait()

# Check that file exist
# Check that a single file exists in the registry.
data = self.get_dot_filebeat()

# Check that offset is set correctly
logFileAbs = os.path.abspath(testfile)
# Hello world text plus newline, multiplied by the number
# of lines and the windows correction applied
assert data[logFileAbs]['offset'] == \
iterations * (11 + len(os.linesep))

# Check that right source field is inside
assert data[logFileAbs]['source'] == logFileAbs

# Check that no additional info is in the file
assert len(data) == 1

# Windows checks
if os.name == "nt":

# TODO: Check for IdxHi, IdxLo, Vol
logFileAbsPath = os.path.abspath(testfile)
record = data[logFileAbsPath]

assert len(data[logFileAbs]) == 3
assert len(data[logFileAbs]['FileStateOS']) == 3
self.assertDictContainsSubset({
"source": logFileAbsPath,
"offset": iterations * line_len,
}, record)
self.assertTrue("FileStateOS" in record)
file_state_os = record["FileStateOS"]

if os.name == "nt":
# Windows checks
# TODO: Check for IdxHi, IdxLo, Vol in FileStateOS on Windows.
self.assertEqual(len(file_state_os), 3)
elif platform.system() == "SunOS":
stat = os.stat(logFileAbsPath)
self.assertEqual(file_state_os["inode"], stat.st_ino)

# Python does not return the same st_dev value as Golang or the
# command line stat tool so just check that it's present.
self.assertTrue("device" in file_state_os)
else:
# Check that inode is set correctly
inode = os.stat(logFileAbs).st_ino
assert data[logFileAbs]['FileStateOS']['inode'] == inode

# Check that device is set correctly
device = os.stat(logFileAbs).st_dev
assert os.name == "nt" or \
data[logFileAbs]['FileStateOS']['device'] == device

assert len(data[logFileAbs]) == 3
assert len(data[logFileAbs]['FileStateOS']) == 2
stat = os.stat(logFileAbsPath)
self.assertDictContainsSubset({
"inode": stat.st_ino,
"device": stat.st_dev,
}, file_state_os)

def test_registrar_files(self):
"""
Expand Down

0 comments on commit f9e2490

Please sign in to comment.