Esempio n. 1
0
 def test_env(self):
     init()
     context.env = {'PREGO_SAMPLE': 'hello'}
     task = Task()
     task.command('echo $PREGO_SAMPLE')
     task.assert_that(task.lastcmd.stdout.content, contains_string('hello'))
     commit()
Esempio n. 2
0
 def test_default_cwd(self):
     init()
     context.cwd = '/tmp'
     task = Task()
     task.command('pwd')
     task.assert_that(task.lastcmd.stdout.content, contains_string('/tmp'))
     commit()
Esempio n. 3
0
 def test_default_env(self):
     init()
     context.env = {'MY_ENV_VAR': '42'}
     task = Task()
     task.command('echo $MY_ENV_VAR')
     task.assert_that(task.lastcmd.stdout.content, contains_string('42'))
     commit()
Esempio n. 4
0
 def test_non_exising_file_contains(self):
     prego.init()
     t = prego.Task()
     t.assert_that(
         prego.File('/tmp/kk').content,
         hamcrest.is_not(hamcrest.contains_string('SOMETHING')))
     prego.commit()
Esempio n. 5
0
 def test_set_read_var(self):
     init()
     context.port = 2030
     task = Task()
     cmd = task.command('echo $port')
     task.assert_that(cmd.stdout.content, contains_string('2030'))
     commit()
Esempio n. 6
0
 def test_cmd_fail_with_outs(self):
     prego.init()
     task = prego.Task()
     task.command('echo STDOUT')
     task.command('echo STDERR >&2')
     task.command('false')
     prego.commit()
Esempio n. 7
0
 def test_file_contains(self):
     open('/tmp/prego-content', 'wt').write('this a sample file for prego')
     prego.init()
     t = prego.Task()
     t.assert_that(
         prego.File('/tmp/prego-content').content,
         hamcrest.contains_string('sample file'))
     prego.commit()
Esempio n. 8
0
    def test_default_timeout(self):
        init()
        context.timeout = 3
        task = Task()
        task.command('true')

        commit()
        self.assertEquals(task.lastcmd.timeout, 3)
Esempio n. 9
0
    def test_ok(self):
        prego.init()
        task = prego.Task()
        cmd = task.command('echo hi')
        task.assert_that(cmd, prego.exits_with(0))
        prego.commit()

        self.assertEquals(Status.OK, task.status)
Esempio n. 10
0
    def test_file_compare(self):
        prego.init()
        a = prego.File('/etc/passwd')
        b = prego.File('/etc/fstab')

        t = prego.Task()
        t.assert_that(a, hamcrest.is_not(b))
        prego.commit()
Esempio n. 11
0
    def test_cmd_wrong_true_and_ls(self):
        prego.init()
        task = prego.Task()
        task.command('wrong')
        task.command('true')

        task2 = prego.Task()
        task2.command('ls')
        prego.commit()
Esempio n. 12
0
 def test_file_permissions(self):
     prego.init()
     t = prego.Task()
     t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o644))
     t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o200))
     t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o400))
     t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o440))
     t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o004))
     prego.commit()
Esempio n. 13
0
    def test_task_is_killed_by_specified_signal(self):
        prego.init()
        task = prego.Task()
        cmd = task.command('sleep 5', signal=SIGINT, timeout=1)

        try:
            prego.commit()
            self.fail()
        except prego.TestFailed:
            self.assertEquals(cmd.returncode, -SIGINT)
Esempio n. 14
0
    def test_default_signal(self):
        init()
        context.signal = signal.SIGINT
        task = Task()
        cmd = task.command('sleep 5', timeout=1)

        try:
            commit()
            self.fail()
        except TestFailed:
            self.assertEquals(cmd.returncode, -signal.SIGINT)
Esempio n. 15
0
    def test_file_compare2(self):

        with open('/tmp/a', 'w') as fd:
            fd.write("foobar")

        with open('/tmp/b', 'w') as fd:
            fd.write("foobar")

        prego.init()
        t = prego.Task()
        t.assert_that(prego.File('/tmp/a'), hamcrest.is_(prego.File('/tmp/b')))
        prego.commit()
Esempio n. 16
0
 def test_err_contains_explicit_filename(self):
     prego.init()
     task = prego.Task()
     cmd = task.command('echo hi >&2', stderr='/tmp/somename.err')
     task.assert_that(cmd.stderr.content, hamcrest.contains_string('hi'))
     prego.commit()
Esempio n. 17
0
 def test_z_read_missing(self):
     init()
     task = Task()
     cmd = task.command('echo $port')
     task.assert_that(cmd.stdout.content, is_not(contains_string('2030')))
     commit()
Esempio n. 18
0
 def test_file_exists_in_cwd(self):
     prego.init()
     t = prego.Task()
     t.assert_that(prego.File('test/$testfilename'), prego.exists())
     prego.commit()
Esempio n. 19
0
 def test_fail_cmd(self):
     prego.init()
     test = prego.Task()
     test.command('false')
     prego.commit()
Esempio n. 20
0
 def test_2_cmds(self):
     prego.init()
     task = prego.Task()
     task.command('true')
     task.command('ls')
     prego.commit()
Esempio n. 21
0
 def test_meet_default_timeout(self):
     prego.init()
     task = prego.Task()
     task.command('sleep 2')
     prego.commit()
Esempio n. 22
0
 def test_zero_tasks_is_ok(self):
     prego.init()
     prego.commit()
     self.assertEquals(0, len(gvars.tasks))
Esempio n. 23
0
 def test_out_contains__explicit_filename(self):
     prego.init()
     task = prego.Task()
     cmd = task.command('echo hi', stdout='/tmp/somename.out')
     task.assert_that(cmd.stdout.content, hamcrest.contains_string('hi'))
     prego.commit()
Esempio n. 24
0
 def test_cmd_false_true(self):
     prego.init()
     task = prego.Task()
     task.command('false')
     task.command('true')
     prego.commit()
Esempio n. 25
0
 def test_out_contains__AUTO(self):
     prego.init()
     task = prego.Task()
     cmd = task.command('echo hi', stdout=prego.AUTO)
     task.assert_that(cmd.stdout.content, hamcrest.contains_string('hi'))
     prego.commit()
Esempio n. 26
0
 def test_file_compare_fail(self):
     prego.init()
     t = prego.Task()
     t.assert_that(prego.File('/etc/fstab'),
                   hamcrest.is_not(prego.File('/etc/passwd')))
     prego.commit()
Esempio n. 27
0
 def test_err_contains__implicit(self):
     prego.init()
     task = prego.Task()
     cmd = task.command('echo hi >&2')
     task.assert_that(cmd.stderr.content, hamcrest.contains_string('hi'))
     prego.commit()