Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Topbeat system test for process username #1

Merged
merged 1 commit into from
Jan 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion topbeat/tests/system/test_procs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from topbeat import BaseTest

import getpass
import re

import os

"""
Contains tests for per process statistics.
Expand Down Expand Up @@ -31,6 +32,7 @@ def test_procs(self):
assert re.match("(?i).*topbeat.test(.exe)? -e -c", output["proc.cmdline"])
assert isinstance(output["proc.state"], basestring)
assert isinstance(output["proc.cpu.start_time"], basestring)
self.check_username(output["proc.username"])

for key in [
"proc.pid",
Expand All @@ -49,3 +51,14 @@ def test_procs(self):
"proc.mem.rss_p",
]:
assert type(output[key]) in [int, float]

def check_username(self, observed, expected = None):
if expected == None:
expected = getpass.getuser()

if os.name == 'nt':
parts = observed.split("\\", 2)
assert len(parts) == 2, "Expected proc.username to be of form DOMAIN\username, but was %s" % observed
observed = parts[1]

assert expected == observed, "proc.username = %s, but expected %s" % (observed, expected)