aspnetcore/test/CommonLibTests/GlobalVersionTests.cpp

154 lines
6.3 KiB
C++

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#include "stdafx.h"
#include "gtest/internal/gtest-port.h"
namespace GlobalVersionTests
{
using ::testing::Test;
namespace fs = std::experimental::filesystem;
class GlobalVersionTest : public Test
{
protected:
void
RemoveFileNamePath(PCWSTR dllPath, PCWSTR expected)
{
std::wstring res = GlobalVersionUtility::RemoveFileNameFromFolderPath(dllPath);
EXPECT_STREQ(res.c_str(), expected);
}
};
TEST_F(GlobalVersionTest, RemovesPathCorrectly)
{
RemoveFileNamePath(L"test\\log.txt", L"test");
RemoveFileNamePath(L"test\\log", L"test");
RemoveFileNamePath(L"C:\\Program Files\\IIS\\aspnetcorev2.dll", L"C:\\Program Files\\IIS");
RemoveFileNamePath(L"test\\log.txt", L"test");
}
TEST(GetRequestHandlerVersions, GetFolders)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
auto res = GlobalVersionUtility::GetRequestHandlerVersions(tempPath.c_str());
EXPECT_EQ(res.size(), 1);
EXPECT_EQ(res.at(0), fx_ver_t(2, 0, 0, std::wstring()));
}
TEST(GetRequestHandlerVersions, GetFolderPreview)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0-preview"));
auto res = GlobalVersionUtility::GetRequestHandlerVersions(tempPath.c_str());
EXPECT_EQ(res.size(), 1);
EXPECT_EQ(res.at(0), fx_ver_t(2, 0, 0, std::wstring(L"-preview")));
}
TEST(GetRequestHandlerVersions, GetFolderManyVersions)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\1.9.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0"));
auto res = GlobalVersionUtility::GetRequestHandlerVersions(tempPath.c_str());
EXPECT_EQ(res.size(), 3);
EXPECT_TRUE(std::find(res.begin(), res.end(), fx_ver_t(1, 9, 0, std::wstring())) != std::end(res));
EXPECT_TRUE(std::find(res.begin(), res.end(), fx_ver_t(2, 0, 0, std::wstring())) != std::end(res));
EXPECT_TRUE(std::find(res.begin(), res.end(), fx_ver_t(2, 1, 0, std::wstring())) != std::end(res));
}
TEST(FindHighestGlobalVersion, HighestVersionWithSingleFolder)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
auto res = GlobalVersionUtility::FindHighestGlobalVersion(tempPath.c_str());
EXPECT_STREQ(res.c_str(), L"2.0.0");
}
TEST(FindHighestGlobalVersion, HighestVersionWithMultipleVersions)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0"));
auto res = GlobalVersionUtility::FindHighestGlobalVersion(tempPath.c_str());
EXPECT_STREQ(res.c_str(), L"2.1.0");
}
TEST(FindHighestGlobalVersion, HighestVersionWithMultipleVersionsPreview)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.2.0-preview"));
auto res = GlobalVersionUtility::FindHighestGlobalVersion(tempPath.c_str());
EXPECT_STREQ(res.c_str(), L"2.2.0-preview");
}
TEST(FindHighestGlobalVersion, HighestVersionWithMultipleVersionNoPreview)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0-preview"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0"));
auto res = GlobalVersionUtility::FindHighestGlobalVersion(tempPath.c_str());
EXPECT_STREQ(res.c_str(), L"2.1.0");
}
TEST(GetGlobalRequestHandlerPath, FindHighestVersionNoHandlerName)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
auto result = GlobalVersionUtility::GetGlobalRequestHandlerPath(tempPath.c_str(), L"", L"aspnetcorev2_outofprocess.dll");
EXPECT_STREQ(result.c_str(), (tempPath + L"2.0.0\\aspnetcorev2_outofprocess.dll").c_str());
}
TEST(GetGlobalRequestHandlerPath, FindHighestVersionPreviewWins)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0-preview"));
auto result = GlobalVersionUtility::GetGlobalRequestHandlerPath(tempPath.c_str(), L"", L"aspnetcorev2_outofprocess.dll");
EXPECT_STREQ(result.c_str(), (tempPath + L"2.1.0-preview\\aspnetcorev2_outofprocess.dll").c_str());
}
TEST(GetGlobalRequestHandlerPath, FindHighestVersionSpecificVersion)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0-preview"));
auto result = GlobalVersionUtility::GetGlobalRequestHandlerPath(tempPath.c_str(), L"2.0.0", L"aspnetcorev2_outofprocess.dll");
EXPECT_STREQ(result.c_str(), (tempPath + L"2.0.0\\aspnetcorev2_outofprocess.dll").c_str());
}
TEST(GetGlobalRequestHandlerPath, FindHighestVersionSpecificPreview)
{
std::wstring tempPath = Helpers::CreateRandomTempDirectory();
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.0.0"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.1.0-preview"));
EXPECT_TRUE(fs::create_directories(tempPath + L"\\2.2.0"));
auto result = GlobalVersionUtility::GetGlobalRequestHandlerPath(tempPath.c_str(), L"2.1.0-preview", L"aspnetcorev2_outofprocess.dll");
EXPECT_STREQ(result.c_str(), (tempPath + L"2.1.0-preview\\aspnetcorev2_outofprocess.dll").c_str());
}
}