-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add snapshot tests support that are executed on forked reposit…
…ory (#9759) * chore: Add snapshot tests support that are executed on forked repository * chore: Add docs for DOCFX_SOURCE_REPOSITORY * chore: change env variable name from DOCFX_SOURCE_REPOSITORY to DOCFX_SOURCE_REPOSITORY_URL --------- Co-authored-by: Yufei Huang <yufeih@live.com>
- Loading branch information
Showing
4 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
test/Docfx.Common.Tests/GitUtilityWithSourceRepoUrlTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Docfx.Common.Git; | ||
using Xunit; | ||
|
||
namespace Docfx.Common.Tests; | ||
|
||
[Collection("docfx STA")] | ||
public class GitUtilityWithSourceRepositoryUrlTest : IDisposable | ||
{ | ||
private readonly string _originalBranchName; | ||
private readonly string _originalSourceRepoUrl; | ||
|
||
private const string ORG_NAME = "dotnet"; | ||
private const string REPO_NAME = "docfx"; | ||
|
||
private const string BRANCH_NAME = "special-branch"; | ||
private const string DOCFX_SOURCE_BRANCH_NAME = nameof(DOCFX_SOURCE_BRANCH_NAME); | ||
private const string DOCFX_SOURCE_REPOSITORY_URL = nameof(DOCFX_SOURCE_REPOSITORY_URL); | ||
|
||
public GitUtilityWithSourceRepositoryUrlTest() | ||
{ | ||
_originalBranchName = Environment.GetEnvironmentVariable(DOCFX_SOURCE_BRANCH_NAME); | ||
_originalSourceRepoUrl = Environment.GetEnvironmentVariable(DOCFX_SOURCE_REPOSITORY_URL); | ||
|
||
Environment.SetEnvironmentVariable(DOCFX_SOURCE_BRANCH_NAME, BRANCH_NAME); | ||
Environment.SetEnvironmentVariable(DOCFX_SOURCE_REPOSITORY_URL, $"https://github.com/{ORG_NAME}/{REPO_NAME}"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Environment.SetEnvironmentVariable(DOCFX_SOURCE_BRANCH_NAME, _originalBranchName); | ||
Environment.SetEnvironmentVariable(DOCFX_SOURCE_REPOSITORY_URL, _originalSourceRepoUrl); | ||
} | ||
|
||
[Fact] | ||
public void TryGetFileDetailTest() | ||
{ | ||
var info = GitUtility.TryGetFileDetail(Directory.GetCurrentDirectory()); | ||
Assert.Equal(BRANCH_NAME, info.Branch); | ||
Assert.Equal("https://github.com/dotnet/docfx", info.Repo); | ||
} | ||
|
||
[Fact] | ||
public void RawContentUrlToContentUrlTest() | ||
{ | ||
string rawUrl = "https://raw.githubusercontent.com/dotnet/docfx/main/README.md"; | ||
string expected = "https://github.com/dotnet/docfx/blob/special-branch/README.md"; | ||
|
||
var result = GitUtility.RawContentUrlToContentUrl(rawUrl); | ||
|
||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://github.com/user/repo.git", "main", "path/to/file.cs", 0, $"https://github.com/{ORG_NAME}/{REPO_NAME}/blob/main/path/to/file.cs")] | ||
[InlineData("https://github.com/user/repo.git", "main", "path/to/file.cs", 10, $"https://github.com/{ORG_NAME}/{REPO_NAME}/blob/main/path/to/file.cs#L10")] | ||
[InlineData("git@github.com:user/repo.git", "main", "path/to/file.cs", 0, $"https://github.com/{ORG_NAME}/{REPO_NAME}/blob/main/path/to/file.cs")] | ||
public void GetSourceUrlTest_GitHub(string repo, string branch, string path, int line, string result) | ||
{ | ||
Assert.Equal(result, GitUtility.GetSourceUrl(new(repo, branch, path, line))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters