def test_multiline_content(self): configs = ['line1', 'line2\nline3\n'] apply_rsyslog_changes( configs=configs, def_fname="default.cfg", cfg_dir=self.tmp) fname = os.path.join(self.tmp, "default.cfg") expected_content = '\n'.join([c for c in configs]) found_content = util.load_file(fname) self.assertEqual(expected_content, found_content)
def test_multiple_files(self): configs = [ '*.* foohost', { 'content': 'abc', 'filename': 'my.cfg' }, { 'content': 'filefoo-content', 'filename': os.path.join(self.tmp, 'mydir/mycfg') }, ] changed = apply_rsyslog_changes(configs=configs, def_fname="default.cfg", cfg_dir=self.tmp) expected = [ (os.path.join(self.tmp, "default.cfg"), "*.* foohost\n"), (os.path.join(self.tmp, "my.cfg"), "abc\n"), (os.path.join(self.tmp, "mydir/mycfg"), "filefoo-content\n"), ] self.assertEqual([f[0] for f in expected], changed) actual = [] for fname, _content in expected: util.load_file(fname) actual.append(( fname, util.load_file(fname), )) self.assertEqual(expected, actual)
def test_simple(self): cfgline = "*.* foohost" changed = apply_rsyslog_changes(configs=[cfgline], def_fname="foo.cfg", cfg_dir=self.tmp) fname = os.path.join(self.tmp, "foo.cfg") self.assertEqual([fname], changed) self.assertEqual(util.load_file(fname), cfgline + "\n")
def test_simple(self): cfgline = "*.* foohost" changed = apply_rsyslog_changes( configs=[cfgline], def_fname="foo.cfg", cfg_dir=self.tmp) fname = os.path.join(self.tmp, "foo.cfg") self.assertEqual([fname], changed) self.assertEqual( util.load_file(fname), cfgline + "\n")
def test_repeat_def(self): configs = ['*.* foohost', "*.warn otherhost"] changed = apply_rsyslog_changes( configs=configs, def_fname="default.cfg", cfg_dir=self.tmp) fname = os.path.join(self.tmp, "default.cfg") self.assertEqual([fname], changed) expected_content = '\n'.join([c for c in configs]) + '\n' found_content = util.load_file(fname) self.assertEqual(expected_content, found_content)
def test_multiple_files(self): configs = [ '*.* foohost', {'content': 'abc', 'filename': 'my.cfg'}, {'content': 'filefoo-content', 'filename': os.path.join(self.tmp, 'mydir/mycfg')}, ] changed = apply_rsyslog_changes( configs=configs, def_fname="default.cfg", cfg_dir=self.tmp) expected = [ (os.path.join(self.tmp, "default.cfg"), "*.* foohost\n"), (os.path.join(self.tmp, "my.cfg"), "abc\n"), (os.path.join(self.tmp, "mydir/mycfg"), "filefoo-content\n"), ] self.assertEqual([f[0] for f in expected], changed) actual = [] for fname, _content in expected: util.load_file(fname) actual.append((fname, util.load_file(fname),)) self.assertEqual(expected, actual)