You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.0 KiB
90 lines
3.0 KiB
// |
|
// Copyright (C) 2017 The Android Open Source Project |
|
// |
|
// Licensed under the Apache License, Version 2.0 (the "License"); |
|
// you may not use this file except in compliance with the License. |
|
// You may obtain a copy of the License at |
|
// |
|
// http://www.apache.org/licenses/LICENSE-2.0 |
|
// |
|
// Unless required by applicable law or agreed to in writing, software |
|
// distributed under the License is distributed on an "AS IS" BASIS, |
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
// See the License for the specific language governing permissions and |
|
// limitations under the License. |
|
// |
|
|
|
#include "update_engine/image_properties.h" |
|
|
|
#include <string> |
|
|
|
#include <base/files/file_util.h> |
|
#include <base/files/scoped_temp_dir.h> |
|
#include <gtest/gtest.h> |
|
|
|
#include "update_engine/common/constants.h" |
|
#include "update_engine/common/test_utils.h" |
|
#include "update_engine/fake_system_state.h" |
|
|
|
using chromeos_update_engine::test_utils::WriteFileString; |
|
using std::string; |
|
|
|
namespace chromeos_update_engine { |
|
|
|
class ImagePropertiesTest : public ::testing::Test { |
|
protected: |
|
void SetUp() override { |
|
// Create a uniquely named test directory. |
|
ASSERT_TRUE(tempdir_.CreateUniqueTempDir()); |
|
osrelease_dir_ = tempdir_.path().Append("etc/os-release.d"); |
|
EXPECT_TRUE(base::CreateDirectory(osrelease_dir_)); |
|
test::SetImagePropertiesRootPrefix(tempdir_.path().value().c_str()); |
|
} |
|
|
|
void WriteOsRelease(const string& key, const string& value) { |
|
ASSERT_TRUE(WriteFileString(osrelease_dir_.Append(key).value(), value)); |
|
} |
|
|
|
FakeSystemState fake_system_state_; |
|
|
|
base::ScopedTempDir tempdir_; |
|
base::FilePath osrelease_dir_; |
|
}; |
|
|
|
TEST_F(ImagePropertiesTest, SimpleTest) { |
|
WriteOsRelease("product_id", "abc"); |
|
WriteOsRelease("system_id", "def"); |
|
WriteOsRelease("product_version", "1.2.3.4"); |
|
WriteOsRelease("system_version", "5.6.7.8"); |
|
ImageProperties props = LoadImageProperties(&fake_system_state_); |
|
EXPECT_EQ("abc", props.product_id); |
|
EXPECT_EQ("def", props.system_id); |
|
EXPECT_EQ("1.2.3.4", props.version); |
|
EXPECT_EQ("5.6.7.8", props.system_version); |
|
EXPECT_EQ("stable-channel", props.current_channel); |
|
EXPECT_EQ(constants::kOmahaDefaultProductionURL, props.omaha_url); |
|
} |
|
|
|
TEST_F(ImagePropertiesTest, IDPrefixTest) { |
|
WriteOsRelease("product_id", "abc:def"); |
|
WriteOsRelease("system_id", "foo:bar"); |
|
ImageProperties props = LoadImageProperties(&fake_system_state_); |
|
EXPECT_EQ("abc:def", props.product_id); |
|
EXPECT_EQ("abc:bar", props.system_id); |
|
} |
|
|
|
TEST_F(ImagePropertiesTest, IDInvalidPrefixTest) { |
|
WriteOsRelease("product_id", "def"); |
|
WriteOsRelease("system_id", "foo:bar"); |
|
ImageProperties props = LoadImageProperties(&fake_system_state_); |
|
EXPECT_EQ("def", props.product_id); |
|
EXPECT_EQ("foo:bar", props.system_id); |
|
|
|
WriteOsRelease("product_id", "abc:def"); |
|
WriteOsRelease("system_id", "bar"); |
|
props = LoadImageProperties(&fake_system_state_); |
|
EXPECT_EQ("abc:def", props.product_id); |
|
EXPECT_EQ("bar", props.system_id); |
|
} |
|
|
|
} // namespace chromeos_update_engine
|
|
|