blob: 717ff924a97d3535465467f817024a5bc2eff23f [file] [log] [blame]
Andrew Lambeceaec02020-02-11 14:16:41 -07001# 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
6import os
7import tempfile
8import unittest
9
10from checker import io_utils
11
C Shapirofd83a5f2020-03-31 08:56:20 -050012from bindings.payload.config_bundle_pb2 import ConfigBundle
Andrew Lambbc029d32020-02-24 12:42:50 -070013from bindings.api.program_pb2 import ProgramList, Program
Andrew Lambeceaec02020-02-11 14:16:41 -070014
15
16class 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 Lambcabb8792020-03-09 13:13:17 -060022 repo_path = tempfile.mkdtemp()
Andrew Lambeceaec02020-02-11 14:16:41 -070023
Andrew Lambcabb8792020-03-09 13:13:17 -060024 os.mkdir(os.path.join(repo_path, 'generated'))
Andrew Lambeceaec02020-02-11 14:16:41 -070025
Andrew Lambcabb8792020-03-09 13:13:17 -060026 self.config_path = os.path.join(repo_path, 'generated',
Andrew Lamb9328c402020-03-05 12:57:59 -070027 'config.binaryproto')
28 with open(self.config_path, 'wb') as f:
Andrew Lambeceaec02020-02-11 14:16:41 -070029 f.write(self.config.SerializeToString())
30
Andrew Lamb9328c402020-03-05 12:57:59 -070031 def test_read_config(self):
Andrew Lambeceaec02020-02-11 14:16:41 -070032 """Tests the binary proto can be read."""
Andrew Lamb9328c402020-03-05 12:57:59 -070033 self.assertEqual(io_utils.read_config(self.config_path), self.config)