Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c983ac6

Browse files
committedAug 22, 2023
add test
1 parent a9e03da commit c983ac6

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed
 

‎src/ApiService/ApiService/OneFuzzTypes/Responses.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public record JobResponse(
103103
StoredUserInfo? UserInfo,
104104
[property: JsonPropertyName("Timestamp")] // must retain capital T for backcompat
105105
DateTimeOffset? Timestamp,
106-
IEnumerable<int>? AdoBugIds
106+
IEnumerable<int> AdoBugIds
107107

108108
// not including UserInfo from Job model
109109
) : BaseResponse() {
@@ -117,7 +117,7 @@ public static JobResponse ForJob(Job j, IEnumerable<IJobTaskInfo>? taskInfo, IEn
117117
TaskInfo: taskInfo,
118118
UserInfo: j.UserInfo,
119119
Timestamp: j.Timestamp,
120-
AdoBugIds: adoBugIds
120+
AdoBugIds: adoBugIds ?? new List<int>()
121121
);
122122
public DateTimeOffset? StartTime => EndTime is DateTimeOffset endTime ? endTime.Subtract(TimeSpan.FromHours(Config.Duration)) : null;
123123
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Microsoft.Extensions.Logging;
2+
using Microsoft.OneFuzz.Service;
3+
namespace IntegrationTests.Fakes;
4+
5+
public sealed class TestAdoNotificationEntryOperations : AdoNotificationEntryOperations {
6+
public TestAdoNotificationEntryOperations(ILogger<AdoNotificationEntryOperations> log, IOnefuzzContext context)
7+
: base(log, context) { }
8+
}

‎src/ApiService/IntegrationTests/Fakes/TestContext.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Net.Http;
45
using Microsoft.Extensions.Caching.Memory;
@@ -65,9 +66,28 @@ public Async.Task InsertAll(params EntityBase[] objs)
6566
InstanceConfig ic => ConfigOperations.Insert(ic),
6667
Notification n => NotificationOperations.Insert(n),
6768
Webhook w => WebhookOperations.Insert(w),
69+
AdoNotificationEntry ado => AdoNotificationEntryOperations.Insert(ado),
6870
_ => throw new NotSupportedException($"You will need to add an TestContext.InsertAll case for {x.GetType()} entities"),
6971
}));
7072

73+
public Async.Task InsertAll(IEnumerable<EntityBase> objs)
74+
=> Async.Task.WhenAll(
75+
objs.Select(x => x switch {
76+
Task t => TaskOperations.Insert(t),
77+
Node n => NodeOperations.Insert(n),
78+
Pool p => PoolOperations.Insert(p),
79+
Job j => JobOperations.Insert(j),
80+
JobResult jr => JobResultOperations.Insert(jr),
81+
Repro r => ReproOperations.Insert(r),
82+
Scaleset ss => ScalesetOperations.Insert(ss),
83+
NodeTasks nt => NodeTasksOperations.Insert(nt),
84+
InstanceConfig ic => ConfigOperations.Insert(ic),
85+
Notification n => NotificationOperations.Insert(n),
86+
Webhook w => WebhookOperations.Insert(w),
87+
AdoNotificationEntry ado => AdoNotificationEntryOperations.Insert(ado),
88+
_ => throw new NotSupportedException($"You will need to add an TestContext.InsertAll case for {x.GetType()} entities"),
89+
}));
90+
7191
// Implementations:
7292

7393
public IMemoryCache Cache { get; }

‎src/ApiService/IntegrationTests/JobsTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,30 @@ await Context.InsertAll(
226226
Assert.Equal(task.Config.Task.Type, returnedTasks[0].Type);
227227

228228
}
229+
230+
[Fact]
231+
public async Async.Task Get_CanFindSpecificJobWithBugs() {
232+
var taskConfig = new TaskConfig(_jobId, new List<Guid>(), new TaskDetails(TaskType.Coverage, 60));
233+
234+
var random = new Random();
235+
var bugs = Enumerable.Range(1, 100).Select(i => random.Next(0, 100)).Distinct().Select(i => new AdoNotificationEntry(_jobId, i, $"test_i")).ToList();
236+
await Context.InsertAll(bugs);
237+
await Context.InsertAll(
238+
new Job(_jobId, JobState.Stopped, _config, null),
239+
new Task(_jobId, Guid.NewGuid(), TaskState.Running, Os.Windows, taskConfig)
240+
);
241+
242+
var func = new Jobs(Context, LoggerProvider.CreateLogger<Jobs>());
243+
244+
var ctx = new TestFunctionContext();
245+
var result = await func.Run(TestHttpRequestData.FromJson("GET", new JobSearch(JobId: _jobId, WithBugs: true)), ctx);
246+
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
247+
248+
var response = BodyAs<JobResponse>(result);
249+
Assert.Equal(_jobId, response.JobId);
250+
Assert.NotNull(response.TaskInfo);
251+
var returnedBugs = response.AdoBugIds.ToList();
252+
Assert.NotEmpty(returnedBugs);
253+
Assert.Equal(bugs.Select(x => x.Id), returnedBugs);
254+
}
229255
}

0 commit comments

Comments
 (0)
This repository has been archived.