blob: 08d08ace73ed02225096007eef762acb19a89766 [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
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070012from chromiumos.config.payload.config_bundle_pb2 import ConfigBundle
13from chromiumos.config.api.program_pb2 import ProgramList, Program
Andrew Lambeceaec02020-02-11 14:16:41 -070014
David Burger54f704e2020-04-30 13:33:47 -060015from google.protobuf import json_format
16
Andrew Lambeceaec02020-02-11 14:16:41 -070017
18class IoUtilsTest(unittest.TestCase):
19 """Tests for io_utils."""
20
21 def setUp(self):
22 self.config = ConfigBundle(
23 programs=ProgramList(value=[Program(name='TestProgram1')]))
Andrew Lambcabb8792020-03-09 13:13:17 -060024 repo_path = tempfile.mkdtemp()
Andrew Lambeceaec02020-02-11 14:16:41 -070025
Andrew Lambcabb8792020-03-09 13:13:17 -060026 os.mkdir(os.path.join(repo_path, 'generated'))
Andrew Lambeceaec02020-02-11 14:16:41 -070027
Andrew Lambcabb8792020-03-09 13:13:17 -060028 self.config_path = os.path.join(repo_path, 'generated',
David Burger54f704e2020-04-30 13:33:47 -060029 'config.jsonproto')
30 json_output = json_format.MessageToJson(self.config,
31 sort_keys=True,
32 use_integers_for_enums=True)
33 with open(self.config_path, 'w') as f:
34 print(json_output, file=f)
Andrew Lambeceaec02020-02-11 14:16:41 -070035
Andrew Lamb9328c402020-03-05 12:57:59 -070036 def test_read_config(self):
David Burger54f704e2020-04-30 13:33:47 -060037 """Tests the json proto can be read."""
Andrew Lamb9328c402020-03-05 12:57:59 -070038 self.assertEqual(io_utils.read_config(self.config_path), self.config)