blob: 0d2727d312c5037a9894072ffcb44210b47e588e [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 Lamb2413c982020-05-29 12:15:36 -060028 self.config_path = os.path.join(repo_path, 'generated', 'config.jsonproto')
29 json_output = json_format.MessageToJson(
30 self.config, sort_keys=True, use_integers_for_enums=True)
David Burger54f704e2020-04-30 13:33:47 -060031 with open(self.config_path, 'w') as f:
32 print(json_output, file=f)
Andrew Lambeceaec02020-02-11 14:16:41 -070033
Andrew Lamb9328c402020-03-05 12:57:59 -070034 def test_read_config(self):
David Burger54f704e2020-04-30 13:33:47 -060035 """Tests the json proto can be read."""
Andrew Lamb9328c402020-03-05 12:57:59 -070036 self.assertEqual(io_utils.read_config(self.config_path), self.config)