public async Task JobsClient_List_With_Filter() { var connection = new Mock <IConnection>(); connection.Setup(c => c.Get <IList <Job> >(ApiUrls.JobsList(), It.IsAny <IDictionary <string, string> >())) .ReturnsAsync(() => { var json = System.IO.File.ReadAllText("./Fixtures/Jobs_List.json"); return(JsonConvert.DeserializeObject <IList <Job> >(json)); }); var logsConnection = new Mock <IConnection>(); var jobsClient = new JobsClient(connection.Object, logsConnection.Object); var result = await jobsClient.List(new JobFilter() { Command = "foo", Container = "bar", Dataset = "foo", MachineType = MachineType.Advanced, Name = "foo", Project = "foo", ProjectId = "foobar", State = JobState.Pending, Workspace = "asdf" }); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); }
public async Task JobsClient_List_HappyPath() { var connection = new Mock <IConnection>(); connection.Setup(c => c.Get <IList <Job> >(ApiUrls.JobsList(), null)) .ReturnsAsync(() => { var json = System.IO.File.ReadAllText("./Fixtures/Jobs_List.json"); return(JsonConvert.DeserializeObject <IList <Job> >(json)); }); var logsConnection = new Mock <IConnection>(); var jobsClient = new JobsClient(connection.Object, logsConnection.Object); var result = await jobsClient.List(); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); }
public async Task RunPreWatchdog(CancellationToken cancellationToken) { const string TestRefEnvVar = "TGS4_GITHUB_REF"; var envVar = Environment.GetEnvironmentVariable(TestRefEnvVar); string workingBranch = null; if (!String.IsNullOrWhiteSpace(envVar)) { workingBranch = envVar; Console.WriteLine($"TEST: Set working branch to '{workingBranch}' from env var '{TestRefEnvVar}'"); } if (workingBranch == null) { workingBranch = "master"; Console.WriteLine($"TEST: Set working branch to default '{workingBranch}'"); } var initalRepo = await repositoryClient.Read(cancellationToken); Assert.IsNotNull(initalRepo); Assert.IsNull(initalRepo.Origin); Assert.IsNull(initalRepo.Reference); Assert.IsNull(initalRepo.RevisionInformation); Assert.IsNull(initalRepo.ActiveJob); const string Origin = "https://github.com/tgstation/tgstation-server"; var cloneRequest = new RepositoryCreateRequest { Origin = new Uri(Origin), Reference = workingBranch, }; var clone = await repositoryClient.Clone(cloneRequest, cancellationToken).ConfigureAwait(false); await ApiAssert.ThrowsException <ConflictException>(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoCloning); Assert.IsNotNull(clone); Assert.AreEqual(cloneRequest.Origin, clone.Origin); Assert.AreEqual(workingBranch, clone.Reference); Assert.IsNull(clone.RevisionInformation); Assert.IsNotNull(clone.ActiveJob); await WaitForJobProgressThenCancel(clone.ActiveJob, 20, cancellationToken).ConfigureAwait(false); var secondRead = await repositoryClient.Read(cancellationToken).ConfigureAwait(false); Assert.IsNotNull(secondRead); Assert.IsNull(secondRead.ActiveJob); clone = await repositoryClient.Clone(cloneRequest, cancellationToken).ConfigureAwait(false); // throwing this small jobs consistency test in here await Task.Delay(TimeSpan.FromSeconds(20), cancellationToken).ConfigureAwait(false); var activeJobs = await JobsClient.ListActive(null, cancellationToken); var allJobs = await JobsClient.List(null, cancellationToken).ConfigureAwait(false); Assert.IsTrue(activeJobs.Any(x => x.Id == clone.ActiveJob.Id)); Assert.IsTrue(allJobs.Any(x => x.Id == clone.ActiveJob.Id)); Assert.IsTrue(activeJobs.First(x => x.Id == clone.ActiveJob.Id).Progress.HasValue); Assert.IsTrue(allJobs.First(x => x.Id == clone.ActiveJob.Id).Progress.HasValue); await WaitForJob(clone.ActiveJob, 9000, false, null, cancellationToken).ConfigureAwait(false); var readAfterClone = await repositoryClient.Read(cancellationToken); Assert.AreEqual(cloneRequest.Origin, readAfterClone.Origin); Assert.AreEqual(workingBranch, readAfterClone.Reference); Assert.IsNotNull(readAfterClone.RevisionInformation); Assert.IsNotNull(readAfterClone.RevisionInformation.ActiveTestMerges); Assert.AreEqual(0, readAfterClone.RevisionInformation.ActiveTestMerges.Count); Assert.IsNotNull(readAfterClone.RevisionInformation.CommitSha); Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha); Assert.IsNotNull(readAfterClone.RevisionInformation.CompileJobs); Assert.AreEqual(0, readAfterClone.RevisionInformation.CompileJobs.Count); Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha); Assert.IsNull(readAfterClone.RevisionInformation.PrimaryTestMerge); Assert.AreEqual(readAfterClone.RevisionInformation.CommitSha, readAfterClone.RevisionInformation.OriginCommitSha); Assert.AreNotEqual(default, readAfterClone.RevisionInformation.Timestamp);