Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 1 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | """Tests for io_utils.""" |
| 5 | |
| 6 | import os |
| 7 | import tempfile |
| 8 | import unittest |
| 9 | |
| 10 | from checker import io_utils |
| 11 | |
C Shapiro | fd83a5f | 2020-03-31 08:56:20 -0500 | [diff] [blame] | 12 | from bindings.payload.config_bundle_pb2 import ConfigBundle |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 13 | from bindings.api.program_pb2 import ProgramList, Program |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | class IoUtilsTest(unittest.TestCase): |
| 17 | """Tests for io_utils.""" |
| 18 | |
| 19 | def setUp(self): |
| 20 | self.config = ConfigBundle( |
| 21 | programs=ProgramList(value=[Program(name='TestProgram1')])) |
Andrew Lamb | cabb879 | 2020-03-09 13:13:17 -0600 | [diff] [blame] | 22 | repo_path = tempfile.mkdtemp() |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 23 | |
Andrew Lamb | cabb879 | 2020-03-09 13:13:17 -0600 | [diff] [blame] | 24 | os.mkdir(os.path.join(repo_path, 'generated')) |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 25 | |
Andrew Lamb | cabb879 | 2020-03-09 13:13:17 -0600 | [diff] [blame] | 26 | self.config_path = os.path.join(repo_path, 'generated', |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 27 | 'config.binaryproto') |
| 28 | with open(self.config_path, 'wb') as f: |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 29 | f.write(self.config.SerializeToString()) |
| 30 | |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 31 | def test_read_config(self): |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 32 | """Tests the binary proto can be read.""" |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 33 | self.assertEqual(io_utils.read_config(self.config_path), self.config) |