~ubuntuone-hackers/conn-check/trunk

« back to all changes in this revision

Viewing changes to tests.py

  • Committer: Tarmac
  • Author(s): Wes Mason
  • Date: 2014-11-26 13:38:34 UTC
  • mfrom: (88.1.9 output-ordering)
  • Revision ID: tarmac-20141126133834-nervbevnamyx921a
[r=james-w] Add buffered output with clearer ordering of output (failed first, skipped last, grouped results)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import operator
 
2
import random
2
3
import testtools
 
4
from StringIO import StringIO
3
5
 
4
6
from testtools import matchers
5
7
 
26
28
from conn_check.main import (
27
29
    build_checks,
28
30
    check_from_description,
 
31
    OrderedOutput,
29
32
    )
30
33
 
31
34
 
113
116
 
114
117
    def test_make_http_check(self):
115
118
        result = make_http_check('http://localhost/')
116
 
        self.assertThat(result,
117
 
            MultiCheckMatcher(strategy=sequential_strategy,
118
 
                subchecks=[
119
 
                    FunctionCheckMatcher('tcp:localhost:80', 'localhost:80'),
120
 
                    FunctionCheckMatcher('http:http://localhost/', 'GET http://localhost/')
121
 
                ]
122
 
            ))
 
119
        self.assertIsInstance(result, PrefixCheckWrapper)
 
120
        self.assertEqual(result.prefix, 'http:http://localhost/:')
 
121
        wrapped = result.wrapped
 
122
        self.assertIsInstance(wrapped, MultiCheck)
 
123
        self.assertIs(wrapped.strategy, sequential_strategy)
 
124
        self.assertEqual(len(wrapped.subchecks), 2)
 
125
        self.assertThat(wrapped.subchecks[0],
 
126
                FunctionCheckMatcher('tcp:localhost:80', 'localhost:80'))
 
127
        self.assertThat(wrapped.subchecks[1],
 
128
                FunctionCheckMatcher('', 'GET http://localhost/'))
123
129
 
124
130
    def test_make_http_check_https(self):
125
131
        result = make_http_check('https://localhost/')
126
 
        self.assertThat(result,
127
 
            MultiCheckMatcher(strategy=sequential_strategy,
128
 
                subchecks=[
129
 
                    FunctionCheckMatcher('tcp:localhost:443', 'localhost:443'),
130
 
                    FunctionCheckMatcher('http:https://localhost/', 'GET https://localhost/')
131
 
                ]
132
 
            ))
 
132
        self.assertIsInstance(result, PrefixCheckWrapper)
 
133
        self.assertEqual(result.prefix, 'http:https://localhost/:')
 
134
        wrapped = result.wrapped
 
135
        self.assertIsInstance(wrapped, MultiCheck)
 
136
        self.assertIs(wrapped.strategy, sequential_strategy)
 
137
        self.assertEqual(len(wrapped.subchecks), 2)
 
138
        self.assertThat(wrapped.subchecks[0],
 
139
                FunctionCheckMatcher('tcp:localhost:443', 'localhost:443'))
 
140
        self.assertThat(wrapped.subchecks[1],
 
141
                FunctionCheckMatcher('', 'GET https://localhost/'))
133
142
 
134
143
    def test_make_amqp_check(self):
135
144
        result = make_amqp_check('localhost', 8080, 'foo',
264
273
        self.assertThat(result,
265
274
                MultiCheckMatcher(strategy=parallel_strategy,
266
275
                    subchecks=[FunctionCheckMatcher('tcp:localhost:8080', 'localhost:8080')]))
 
276
 
 
277
    def test_ordered_output(self):
 
278
        lines = [
 
279
            'SKIPPED: xyz3:localhost:666\n',
 
280
            'bar2:localhost:8080 FAILED: error\n',
 
281
            'SKIPPED: foo2:localhost:8080\n',
 
282
            'baz2:localhost:42 OK\n',
 
283
            'SKIPPED: bar2:localhost:8080\n',
 
284
            'xyz2:localhost:666 FAILED: error\n',
 
285
            'xyz1:localhost:666 OK\n',
 
286
            'foo1:localhost:8080 FAILED: error\n',
 
287
            'baz1:localhost:42 OK\n',
 
288
        ]
 
289
        expected = (
 
290
            'bar2:localhost:8080 FAILED: error\n'
 
291
            'foo1:localhost:8080 FAILED: error\n'
 
292
            'xyz2:localhost:666 FAILED: error\n'
 
293
            'baz1:localhost:42 OK\n'
 
294
            'baz2:localhost:42 OK\n'
 
295
            'xyz1:localhost:666 OK\n'
 
296
            'SKIPPED: bar2:localhost:8080\n'
 
297
            'SKIPPED: foo2:localhost:8080\n'
 
298
            'SKIPPED: xyz3:localhost:666\n'
 
299
        )
 
300
 
 
301
        output = OrderedOutput(StringIO())
 
302
        map(output.write, lines)
 
303
        output.flush()
 
304
        self.assertEqual(expected, output.output.getvalue())
 
305
 
 
306
        output = OrderedOutput(StringIO())
 
307
        random.shuffle(lines)
 
308
        map(output.write, lines)
 
309
        output.flush()
 
310
        self.assertEqual(expected, output.output.getvalue())