blob: 8ae8bec82c993c52d6f40bdbf3b2034fad87b25c [file] [log] [blame]
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <list>
#include <string>
#include <utility>
#include <base/files/file_path.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "diagnostics/cros_healthd/utils/storage/device_lister.h"
#include "diagnostics/cros_healthd/utils/storage/mock/mock_platform.h"
using testing::Return;
using testing::UnorderedElementsAre;
namespace diagnostics {
namespace {
constexpr char kFakeRoot[] = "cros_healthd/utils/storage/testdata/";
}
TEST(StorageDeviceListerTest, EmmcRoot) {
auto mock_platform = std::make_unique<MockPlatform>();
EXPECT_CALL(*mock_platform, GetRootDeviceName())
.WillRepeatedly(Return("mmcblk0"));
StorageDeviceLister lister(std::move(mock_platform));
auto result = lister.ListDevices(base::FilePath(kFakeRoot));
EXPECT_THAT(result,
UnorderedElementsAre("mmcblk0", "nvme0n1", "nvme0n2",
"missing_model_and_name_test",
"name_file_test", "model_file_test"));
}
TEST(StorageDeviceListerTest, NvmeRoot) {
auto mock_platform = std::make_unique<MockPlatform>();
EXPECT_CALL(*mock_platform, GetRootDeviceName())
.WillRepeatedly(Return("nvme0n1"));
StorageDeviceLister lister(std::move(mock_platform));
auto result = lister.ListDevices(base::FilePath(kFakeRoot));
EXPECT_THAT(result, UnorderedElementsAre(
"nvme0n1", "nvme0n2", "missing_model_and_name_test",
"name_file_test", "model_file_test"));
}
} // namespace diagnostics