blob: dcb8b73cf804369f987bcf1ea076ed1fdac84ee2 [file] [log] [blame]
Michael Mortensen3e86c1e2019-11-21 15:51:54 -07001# -*- coding: utf-8 -*-
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Unittests for build_api.py"""
7
8from __future__ import print_function
9
10import os
11
12from chromite.api import router as router_lib
13from chromite.lib import cros_test_lib
14from chromite.lib import osutils
15from chromite.scripts import build_api
16
17
18class BuildApiScriptTest(cros_test_lib.MockTempDirTestCase):
19 """Tests for main()"""
20
21 def setUp(self):
22 self.find_mock = self.PatchObject(router_lib.Router, 'Route')
23 self.input_json = os.path.join(self.tempdir, 'input.json')
24 self.output_json = os.path.join(self.tempdir, 'output.json')
25 self.tee_log = os.path.join(self.tempdir, 'tee_out.txt')
26 input_json_contents = """
27{
28 "buildTarget": {
29 "name": "amd64-generic"
30 }
31}
32 """
33 osutils.WriteFile(self.input_json, input_json_contents)
34
35 def testSmoke(self):
36 """Basic sanity check"""
37 build_api.main(['--input-json', self.input_json,
38 '--output-json', self.output_json,
39 'chromite.api.PackageService/GetTargetVersions'])
40
41 def testTee(self):
42 """Call build_api with tee-log set, verify log contents."""
43 build_api.main(['--input-json', self.input_json,
44 '--output-json', self.output_json,
45 '--tee-log', self.tee_log,
46 'chromite.api.PackageService/GetTargetVersions'])
47 contents = osutils.ReadFile(self.tee_log)
48 self.assertIn('Teeing stdout', contents)