blob: 0090fbf87e44dd5e0b83b9aa68eaebdcaadc4786 [file] [log] [blame]
Mike Frysinger1dad0972019-02-23 18:36:37 -05001// Copyright 2019 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
5#include "dev-install/dev_install.h"
6
7#include <gmock/gmock.h>
8#include <gtest/gtest.h>
9
10using ::testing::_;
11using ::testing::Return;
12
13namespace dev_install {
14
15namespace {
16
17class DevInstallMock : public DevInstall {
18 public:
19 MOCK_METHOD1(Exec, int(const std::vector<const char*>&));
Mike Frysingeree5af6e2019-02-23 23:47:03 -050020 MOCK_CONST_METHOD0(IsDevMode, bool());
Mike Frysinger1dad0972019-02-23 18:36:37 -050021};
22
23class DevInstallTest : public ::testing::Test {
Mike Frysingeree5af6e2019-02-23 23:47:03 -050024 public:
25 void SetUp() override {
26 // Set the default to dev mode enabled. Most tests want that.
27 ON_CALL(dev_install_, IsDevMode()).WillByDefault(Return(true));
28 }
29
Mike Frysinger1dad0972019-02-23 18:36:37 -050030 protected:
31 DevInstallMock dev_install_;
32};
33
34} // namespace
35
36// Check default run through.
37TEST_F(DevInstallTest, Run) {
38 EXPECT_CALL(dev_install_, Exec(_)).WillOnce(Return(1234));
39 EXPECT_EQ(1234, dev_install_.Run());
40}
41
Mike Frysingeree5af6e2019-02-23 23:47:03 -050042// Systems not in dev mode should abort.
43TEST_F(DevInstallTest, NonDevMode) {
44 EXPECT_CALL(dev_install_, IsDevMode()).WillOnce(Return(false));
45 EXPECT_CALL(dev_install_, Exec(_)).Times(0);
46 EXPECT_EQ(2, dev_install_.Run());
47}
48
Mike Frysinger1dad0972019-02-23 18:36:37 -050049} // namespace dev_install