~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to tests/test_gotestwin.py

  • Committer: Curtis Hovey
  • Date: 2015-06-16 20:18:37 UTC
  • mto: This revision was merged to the branch mainline in revision 995.
  • Revision ID: curtis@canonical.com-20150616201837-l44eyp22o501g6ee
Ensure the env name is in the config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import contextlib
2
 
import json
3
 
from mock import (
4
 
    call,
5
 
    patch,
6
 
)
7
 
import os
8
 
 
9
 
import gotestwin
10
 
from tests import TestCase
11
 
from utility import temp_dir
12
 
 
13
 
 
14
 
JUJU_CI_PATH = os.path.join(gotestwin.SCRIPTS, 'jujuci.py')
15
 
JUJU_HOME = os.path.join(gotestwin.SCRIPTS, '..', 'cloud-city')
16
 
 
17
 
 
18
 
@contextlib.contextmanager
19
 
def working_directory(path):
20
 
    curdir = os.getcwd()
21
 
    try:
22
 
        os.chdir(path)
23
 
        yield
24
 
    finally:
25
 
        os.chdir(curdir)
26
 
 
27
 
 
28
 
class GoTestWinTestCase(TestCase):
29
 
 
30
 
    @patch('subprocess.check_output', return_value='path/foo.tar.gz')
31
 
    @patch('subprocess.check_call')
32
 
    def test_main_with_revision(self, cc_mock, co_mock):
33
 
        with temp_dir() as base:
34
 
            with working_directory(base):
35
 
                gotestwin.main(['host', '1234'])
36
 
                self.assertTrue(os.path.exists('temp-config.yaml'))
37
 
                with open('temp-config.yaml') as f:
38
 
                    data = json.load(f)
39
 
        self.assertEqual(
40
 
            ['python', 'ci/gotesttarfile.py', '-v', '-g', 'go.exe', '-p',
41
 
             'github.com/juju/juju', '--remove', 'ci/foo.tar.gz'],
42
 
            data['command'])
43
 
        co_mock.assert_called_once_with(
44
 
            [JUJU_CI_PATH, 'get', '-b', '1234', 'build-revision',
45
 
             '*.tar.gz', './'])
46
 
        tarfile_call = call(
47
 
            [JUJU_CI_PATH, 'get-build-vars', '--summary', '1234'])
48
 
        gotest_call = call(
49
 
            ['workspace-run', '-v', '-i', 'cloud-city/staging-juju-rsa',
50
 
             'temp-config.yaml', 'Administrator@host'])
51
 
        self.assertEqual([tarfile_call, gotest_call], cc_mock.call_args_list)
52
 
 
53
 
    @patch('subprocess.check_call')
54
 
    def test_main_with_tarfile_and_package(self, cc_mock):
55
 
        with temp_dir() as base:
56
 
            with working_directory(base):
57
 
                gotestwin.main(
58
 
                    ['host', 'bar.tar.gz', 'github.com/juju/juju/cmd'])
59
 
                self.assertTrue(os.path.exists('temp-config.yaml'))
60
 
                with open('temp-config.yaml') as f:
61
 
                    data = json.load(f)
62
 
        self.assertEqual(
63
 
            ['python', 'ci/gotesttarfile.py', '-v', '-g', 'go.exe', '-p',
64
 
             'github.com/juju/juju/cmd', '--remove', 'ci/bar.tar.gz'],
65
 
            data['command'])
66
 
        cc_mock.assert_called_once_with(
67
 
            ['workspace-run', '-v', '-i', 'cloud-city/staging-juju-rsa',
68
 
             'temp-config.yaml', 'Administrator@host'])