Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates and fixes for tests, changing master to main and adding flaky tests marker #2511

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Octokit.Tests.Integration/Clients/BlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public BlobClientTests()
var github = Helper.GetAuthenticatedClient();
_fixture = github.Git.Blob;

_context = github.CreateRepositoryContext("public-repo").Result;
_context = github.CreateRepositoryContextWithAutoInit("public-repo").Result;
}

[IntegrationTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public TheCreateReactionMethod()
{
_github = Helper.GetAuthenticatedClient();

_context = _github.CreateRepositoryContext("public-repo").Result;
_context = _github.CreateRepositoryContextWithAutoInit("public-repo").Result;
}

private async Task<Commit> SetupCommitForRepository(IGitHubClient client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public TheCreateMethod()
{
_github = Helper.GetAuthenticatedClient();

_context = _github.CreateRepositoryContext("public-repo").Result;
_context = _github.CreateRepositoryContextWithAutoInit("public-repo").Result;
}

[IntegrationTest]
Expand Down
4 changes: 2 additions & 2 deletions Octokit.Tests.Integration/Clients/CommitsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public async Task CanCreateAndRetrieveCommit()
var github = Helper.GetAuthenticatedClient();
var fixture = github.Git.Commit;

using (var context = await github.CreateRepositoryContext("public-repo"))
using (var context = await github.CreateRepositoryContextWithAutoInit("public-repo"))
{
var owner = context.Repository.Owner.Login;

Expand Down Expand Up @@ -67,7 +67,7 @@ public async Task CanCreateAndRetrieveCommitWithRepositoryId()
var github = Helper.GetAuthenticatedClient();
var fixture = github.Git.Commit;

using (var context = await github.CreateRepositoryContext("public-repo"))
using (var context = await github.CreateRepositoryContextWithAutoInit("public-repo"))
{
var owner = context.Repository.Owner.Login;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public DeploymentStatusClientTests()
var github = Helper.GetAuthenticatedClient();

_deploymentsClient = github.Repository.Deployment;
_context = github.CreateRepositoryContext("public-repo").Result;
_context = github.CreateRepositoryContextWithAutoInit("public-repo").Result;

var blob = new NewBlob
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public DeploymentsClientTests()
var github = Helper.GetAuthenticatedClient();

_deploymentsClient = github.Repository.Deployment;
_context = github.CreateRepositoryContext("public-repo").Result;
_context = github.CreateRepositoryContextWithAutoInit("public-repo").Result;

var blob = new NewBlob
{
Expand Down
6 changes: 3 additions & 3 deletions Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task ReturnsIssueCommentWithRepositoryId()
[IntegrationTest]
public async Task CanGetReactionPayload()
{
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
using (var context = await _github.CreateRepositoryContextWithAutoInit(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
{
// Create a test issue
var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName);
Expand Down Expand Up @@ -217,7 +217,7 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId()
public async Task CanGetReactionPayload()
{
var numberToCreate = 2;
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
using (var context = await _github.CreateRepositoryContextWithAutoInit(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
{
var commentIds = new List<int>();

Expand Down Expand Up @@ -402,7 +402,7 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId()
public async Task CanGetReactionPayload()
{
var numberToCreate = 2;
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
using (var context = await _github.CreateRepositoryContextWithAutoInit(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
{
var commentIds = new List<int>();

Expand Down
4 changes: 2 additions & 2 deletions Octokit.Tests.Integration/Clients/IssuesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ public async Task GetAllForOrganizationContainsRepositoryData()
[IntegrationTest]
public async Task CanGetReactionPayload()
{
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssuesReactionTests")))
using (var context = await _github.CreateRepositoryContextWithAutoInit(Helper.MakeNameWithTimestamp("IssuesReactionTests")))
{
// Create a test issue with reactions
var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName);
Expand All @@ -1312,7 +1312,7 @@ public async Task CanGetReactionPayload()
public async Task CanGetReactionPayloadForMultipleIssues()
{
var numberToCreate = 2;
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssuesReactionTests")))
using (var context = await _github.CreateRepositoryContextWithAutoInit(Helper.MakeNameWithTimestamp("IssuesReactionTests")))
{
var issueNumbers = new List<int>();

Expand Down
24 changes: 12 additions & 12 deletions Octokit.Tests.Integration/Clients/MergingClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,49 @@ public MergingClientTests()
};

_fixture = _github.Repository.Merging;
_context = _github.CreateRepositoryContext("public-repo").Result;
_context = _github.CreateRepositoryContextWithAutoInit("public-repo").Result;
}

[IntegrationTest]
public async Task CanCreateMerge()
{
await CreateTheWorld();

var newMerge = new NewMerge("master", branchName) { CommitMessage = "merge commit to master from integrationtests" };
var newMerge = new NewMerge("main", branchName) { CommitMessage = "merge commit to main from integrationtests" };

var merge = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newMerge);
Assert.NotNull(merge);
Assert.NotNull(merge.Commit);
Assert.Equal("merge commit to master from integrationtests", merge.Commit.Message);
Assert.Equal("merge commit to main from integrationtests", merge.Commit.Message);
}

[IntegrationTest]
public async Task CanCreateMergeWithRepositoryId()
{
await CreateTheWorld();

var newMerge = new NewMerge("master", branchName) { CommitMessage = "merge commit to master from integrationtests" };
var newMerge = new NewMerge("main", branchName) { CommitMessage = "merge commit to main from integrationtests" };

var merge = await _fixture.Create(_context.Repository.Id, newMerge);
Assert.NotNull(merge);
Assert.NotNull(merge.Commit);
Assert.Equal("merge commit to master from integrationtests", merge.Commit.Message);
Assert.Equal("merge commit to main from integrationtests", merge.Commit.Message);
}

async Task CreateTheWorld()
{
var master = await _github.Git.Reference.Get(Helper.UserName, _context.RepositoryName, "heads/master");
var main = await _github.Git.Reference.Get(Helper.UserName, _context.RepositoryName, "heads/main");

// create new commit for master branch
var newMasterTree = await CreateTree(new Dictionary<string, string> { { "README.md", "Hello World! I want to be overwritten by featurebranch!" } });
var newMaster = await CreateCommit("baseline for merge", newMasterTree.Sha, master.Object.Sha);
// create new commit for main branch
var newMainTree = await CreateTree(new Dictionary<string, string> { { "README.md", "Hello World! I want to be overwritten by featurebranch!" } });
var newMain = await CreateCommit("baseline for merge", newMainTree.Sha, main.Object.Sha);

// update master
await _github.Git.Reference.Update(Helper.UserName, _context.RepositoryName, "heads/master", new ReferenceUpdate(newMaster.Sha));
// update main
await _github.Git.Reference.Update(Helper.UserName, _context.RepositoryName, "heads/main", new ReferenceUpdate(newMain.Sha));

// create new commit for feature branch
var featureBranchTree = await CreateTree(new Dictionary<string, string> { { "README.md", "I am overwriting this blob with something new" } });
var featureBranchCommit = await CreateCommit("this is the commit to merge", featureBranchTree.Sha, newMaster.Sha);
var featureBranchCommit = await CreateCommit("this is the commit to merge", featureBranchTree.Sha, newMain.Sha);

// create branch
await _github.Git.Reference.Create(Helper.UserName, _context.RepositoryName, new NewReference("refs/heads/my-branch", featureBranchCommit.Sha));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public TheCreateMethod()
{
_github = Helper.GetAuthenticatedClient();

_context = _github.CreateRepositoryContext("public-repo").Result;
_context = _github.CreateRepositoryContextWithAutoInit("public-repo").Result;
}

[IntegrationTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PullRequestReviewCommentReactionsClientTests()
_client = _github.PullRequest.ReviewComment;

// We'll create a pull request that can be used by most tests
_context = _github.CreateRepositoryContext("test-repo").Result;
_context = _github.CreateUserRepositoryContext("test-repo").Result;
}

[IntegrationTest]
Expand Down Expand Up @@ -339,60 +339,6 @@ public async Task CanCreateReactionWithRepositoryId()
Assert.Equal(commentFromGitHub.User.Id, pullRequestReviewCommentReaction.User.Id);
}

[IntegrationTest]
public async Task CanDeleteReaction()
{
var pullRequest = await CreatePullRequest(_context);

const string body = "A review comment message";
const int position = 1;

var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number);

var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id);

AssertComment(commentFromGitHub, body, position);

foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
{
var newReaction = new NewReaction(reactionType);

var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReaction);
await _github.Reaction.PullRequestReviewComment.Delete(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, reaction.Id);
}

var allReactions = await _github.Reaction.PullRequestReviewComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id);

Assert.Empty(allReactions);
}

[IntegrationTest]
public async Task CanDeleteReactionWithRepositoryId()
{
var pullRequest = await CreatePullRequest(_context);

const string body = "A review comment message";
const int position = 1;

var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number);

var commentFromGitHub = await _client.GetComment(_context.RepositoryId, createdComment.Id);

AssertComment(commentFromGitHub, body, position);

foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
{
var newReaction = new NewReaction(reactionType);

var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryId, commentFromGitHub.Id, newReaction);
await _github.Reaction.PullRequestReviewComment.Delete(_context.RepositoryId, commentFromGitHub.Id, reaction.Id);
}

var allReactions = await _github.Reaction.PullRequestReviewComment.GetAll(_context.RepositoryId, commentFromGitHub.Id);

Assert.Empty(allReactions);
}

/// <summary>
/// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request)
/// </summary>
Expand All @@ -403,11 +349,11 @@ async Task<PullRequestData> CreatePullRequest(RepositoryContext context)

// Creating a commit in master

var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/main", "A master commit message");
var createdCommitInMain = await CreateCommit(repoName, "Hello World!", "README.md", "heads/main", "A main commit message");

// Creating a branch

var newBranch = new NewReference(branchRef, createdCommitInMaster.Sha);
var newBranch = new NewReference(branchRef, createdCommitInMain.Sha);
await _github.Git.Reference.Create(Helper.UserName, repoName, newBranch);

// Creating a commit in the branch
Expand All @@ -416,7 +362,7 @@ async Task<PullRequestData> CreatePullRequest(RepositoryContext context)

// Creating a pull request

var pullRequest = new NewPullRequest("Nice title for the pull request", branchName, "main");
var pullRequest = new NewPullRequest("Nice title for the pull request", branchName, "master");
var createdPullRequest = await _github.PullRequest.Create(Helper.UserName, repoName, pullRequest);

var data = new PullRequestData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public PullRequestReviewCommentsClientTests()
_client = _github.PullRequest.ReviewComment;

// We'll create a pull request that can be used by most tests
_context = _github.CreateRepositoryContext("test-repo").Result;
_context = _github.CreateRepositoryContextWithAutoInit("test-repo").Result;
}

[IntegrationTest]
Expand Down Expand Up @@ -844,7 +844,7 @@ static void AssertComments(IReadOnlyList<PullRequestReviewComment> comments, Lis
}

/// <summary>
/// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request)
/// Creates the base state for testing (creates a repo, a commit in main, a branch, a commit in the branch and a pull request)
/// </summary>
/// <returns></returns>
async Task<PullRequestData> CreatePullRequest(RepositoryContext context, string branch = branchName)
Expand All @@ -855,13 +855,13 @@ async Task<PullRequestData> CreatePullRequest(RepositoryContext context, string

var repoName = context.RepositoryName;

// Creating a commit in master
// Creating a commit in main

var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/master", "A master commit message");
var createdCommitInMain = await CreateCommit(repoName, "Hello World!", "README.md", "heads/main", "A main commit message");

// Creating a branch

var newBranch = new NewReference(branchRef, createdCommitInMaster.Sha);
var newBranch = new NewReference(branchRef, createdCommitInMain.Sha);
await _github.Git.Reference.Create(Helper.UserName, repoName, newBranch);

// Creating a commit in the branch
Expand All @@ -870,7 +870,7 @@ async Task<PullRequestData> CreatePullRequest(RepositoryContext context, string

// Creating a pull request

var pullRequest = new NewPullRequest("Nice title for the pull request", branch, "master");
var pullRequest = new NewPullRequest("Nice title for the pull request", branch, "main");
var createdPullRequest = await _github.PullRequest.Create(Helper.UserName, repoName, pullRequest);

var data = new PullRequestData
Expand Down Expand Up @@ -926,7 +926,7 @@ class PullRequestData
public async Task CanGetReactionPayloadForPullRequestReviews()
{
int numberToCreate = 2;
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("PullRequestReviewCommentsReactionTests")))
using (var context = await _github.CreateRepositoryContextWithAutoInit(Helper.MakeNameWithTimestamp("PullRequestReviewCommentsReactionTests")))
{
var commentIds = new List<int>();

Expand Down Expand Up @@ -965,7 +965,7 @@ public async Task CanGetReactionPayloadForPullRequestReviews()
public async Task CanGetReactionPayloadForRepositoryPullRequestReviews()
{
int numberToCreate = 2;
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("PullRequestReviewCommentsReactionTests")))
using (var context = await _github.CreateRepositoryContextWithAutoInit(Helper.MakeNameWithTimestamp("PullRequestReviewCommentsReactionTests")))
{
var commentIds = new List<int>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PullRequestReviewRequestClientTestsBase()

_client = _github.PullRequest.ReviewRequest;

_context = _github.CreateRepositoryContext("test-repo").Result;
_context = _github.CreateRepositoryContextWithAutoInit("test-repo").Result;

Task.WaitAll(_collaboratorLogins.Select(AddCollaborator).ToArray());
}
Expand Down Expand Up @@ -144,18 +144,18 @@ public async Task CreatesRequestsWithRepositoryId()

static async Task<int> CreateTheWorld(IGitHubClient github, RepositoryContext context, bool createReviewRequests = true)
{
var master = await github.Git.Reference.Get(context.RepositoryOwner, context.RepositoryName, "heads/master");
var main = await github.Git.Reference.Get(context.RepositoryOwner, context.RepositoryName, "heads/main");

// create new commit for master branch
var newMasterTree = await CreateTree(github, context, new Dictionary<string, string> { { "README.md", "Hello World!" } });
var newMaster = await CreateCommit(github, context, "baseline for pull request", newMasterTree.Sha, master.Object.Sha);
// create new commit for main branch
var newMainTree = await CreateTree(github, context, new Dictionary<string, string> { { "README.md", "Hello World!" } });
var newMain = await CreateCommit(github, context, "baseline for pull request", newMainTree.Sha, main.Object.Sha);

// update master
await github.Git.Reference.Update(context.RepositoryOwner, context.RepositoryName, "heads/master", new ReferenceUpdate(newMaster.Sha));
// update main
await github.Git.Reference.Update(context.RepositoryOwner, context.RepositoryName, "heads/main", new ReferenceUpdate(newMain.Sha));

// create new commit for feature branch
var featureBranchTree = await CreateTree(github, context, new Dictionary<string, string> { { "README.md", "I am overwriting this blob with something new" } });
var featureBranchCommit = await CreateCommit(github, context, "this is the commit to merge into the pull request", featureBranchTree.Sha, newMaster.Sha);
var featureBranchCommit = await CreateCommit(github, context, "this is the commit to merge into the pull request", featureBranchTree.Sha, newMain.Sha);

var featureBranchTree2 = await CreateTree(github, context, new Dictionary<string, string> { { "README.md", "I am overwriting this blob with something new a 2nd time" } });
var featureBranchCommit2 = await CreateCommit(github, context, "this is a 2nd commit to merge into the pull request", featureBranchTree2.Sha, featureBranchCommit.Sha);
Expand All @@ -164,7 +164,7 @@ static async Task<int> CreateTheWorld(IGitHubClient github, RepositoryContext co
await github.Git.Reference.Create(context.RepositoryOwner, context.RepositoryName, new NewReference("refs/heads/my-branch", featureBranchCommit2.Sha));

// create a pull request
var pullRequest = new NewPullRequest("Nice title for the pull request", "my-branch", "master");
var pullRequest = new NewPullRequest("Nice title for the pull request", "my-branch", "main");
var createdPullRequest = await github.PullRequest.Create(context.RepositoryOwner, context.RepositoryName, pullRequest);

// Create review requests (optional)
Expand Down
Loading