Skip to content

Commit

Permalink
increase code coverage project variables feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Ramon Garcia authored and Cristian Ramon Garcia committed Oct 1, 2019
1 parent 9443981 commit 3165451
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/GitLabApiClient.Test/ProjectsClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using GitLabApiClient.Internal.Queries;
Expand All @@ -20,6 +21,7 @@ public class ProjectsClientTest : IAsyncLifetime
{
private List<int> ProjectIdsToClean { get; } = new List<int>();
private List<int> MilestoneIdsToClean { get; } = new List<int>();
private List<string> VariableIdsToClean { get; } = new List<string>();

private readonly ProjectsClient _sut = new ProjectsClient(
GitLabApiHelper.GetFacade(),
Expand Down Expand Up @@ -73,6 +75,37 @@ public async Task ProjectMilestonesRetrieved()
m.Description == "description1");
}

[Fact]
public async Task ProjectVariablesRetrieved()
{
//arrange
var createdVariable = await _sut.CreateVariableAsync(new CreateVariableRequest
{
ProjectId = GitLabApiHelper.TestProjectId.ToString(),
VariableType = "env_var",
Key = "SOME_VAR_KEY",
Value = "VALUE_VAR",
EnvironmentScope = "*",
Masked = true,
Protected = true
});
VariableIdsToClean.Add(createdVariable.Key);

//act
var variables = await _sut.GetVariablesAsync(GitLabApiHelper.TestProjectId);
var variable = variables.First(v => v.Key == createdVariable.Key);

//assert
variables.Should().NotBeEmpty();
variable.Should().Match<Variable>(v =>
v.VariableType == createdVariable.VariableType &&
v.Key == createdVariable.Key &&
v.Value == createdVariable.Value &&
v.EnvironmentScope == createdVariable.EnvironmentScope &&
v.Masked == createdVariable.Masked &&
v.Protected == createdVariable.Protected);
}

[Fact]
public async Task ProjectRetrievedByName()
{
Expand Down Expand Up @@ -138,6 +171,7 @@ public async Task ProjectVariableCreatedUpdateDeleted()
&& v.Masked == request.Masked
&& v.Protected == request.Protected);

VariableIdsToClean.Add(request.Key);

var updateRequest = new UpdateProjectVariableRequest
{
Expand Down Expand Up @@ -302,6 +336,9 @@ private async Task CleanupProjects()

foreach (int projectId in ProjectIdsToClean)
await _sut.DeleteAsync(projectId);

foreach (string variableId in VariableIdsToClean)
await _sut.DeleteVariableAsync(GitLabApiHelper.TestProjectId, variableId);
}

private static string GetRandomProjectName() => "test-gitlabapiclient" + Path.GetRandomFileName();
Expand Down

0 comments on commit 3165451

Please sign in to comment.