public async Task OnboardingRequestsWithDuplicateDigest_Failed() { DateTime baselineTime = DateTime.Now; const string platformTag1 = "platformTag1"; const string repo1 = "repo1"; const string platformDigest1 = "platformDigest1"; const string tag1aOnboardingRequestId = "onboard request1"; const string tag1bOnboardingRequestId = "onboard request2"; Mock <IMcrStatusClient> statusClientMock = new Mock <IMcrStatusClient>(); ImageStatus platformTag1aImageStatus = new ImageStatus { Tag = platformTag1, TargetRepository = repo1, QueueTime = baselineTime.AddHours(1), OverallStatus = StageStatus.Processing, OnboardingRequestId = tag1aOnboardingRequestId }; ImageStatus platformTag1bImageStatus = new ImageStatus { Tag = platformTag1, TargetRepository = repo1, QueueTime = baselineTime.AddHours(2), OverallStatus = StageStatus.Processing, OnboardingRequestId = tag1bOnboardingRequestId }; Dictionary <string, IEnumerator <ImageResult> > imageResultMapping = new Dictionary <string, IEnumerator <ImageResult> > { { platformDigest1, new List <ImageResult> { new ImageResult { Digest = platformDigest1, Value = new List <ImageStatus> { platformTag1aImageStatus, platformTag1bImageStatus, } }, new ImageResult { Digest = platformDigest1, Value = new List <ImageStatus> { Clone(platformTag1aImageStatus, StageStatus.Failed), platformTag1bImageStatus, } }, new ImageResult { Digest = platformDigest1, Value = new List <ImageStatus> { Clone(platformTag1aImageStatus, StageStatus.Failed), Clone(platformTag1bImageStatus, StageStatus.Failed), } } }.GetEnumerator() } }; statusClientMock .Setup(o => o.GetImageResultAsync(It.IsAny <string>())) .ReturnsAsync((string digest) => { IEnumerator <ImageResult> enumerator = imageResultMapping[digest]; if (enumerator.MoveNext()) { return(enumerator.Current); } return(null); }); statusClientMock .Setup(o => o.GetImageResultDetailedAsync(platformDigest1, tag1aOnboardingRequestId)) .ReturnsAsync(new ImageResultDetailed { CommitDigest = platformDigest1, OnboardingRequestId = tag1aOnboardingRequestId, OverallStatus = StageStatus.Failed, Tag = platformTag1, TargetRepository = repo1, Substatus = new ImageSubstatus() }); statusClientMock .Setup(o => o.GetImageResultDetailedAsync(platformDigest1, tag1bOnboardingRequestId)) .ReturnsAsync(new ImageResultDetailed { CommitDigest = platformDigest1, OnboardingRequestId = tag1bOnboardingRequestId, OverallStatus = StageStatus.Failed, Tag = platformTag1, TargetRepository = repo1, Substatus = new ImageSubstatus() }); const string tenant = "my tenant"; const string clientId = "my id"; const string clientSecret = "very secret"; Mock <IEnvironmentService> environmentServiceMock = new Mock <IEnvironmentService>(); WaitForMcrImageIngestionCommand command = new WaitForMcrImageIngestionCommand( Mock.Of <ILoggerService>(), CreateMcrStatusClientFactory(tenant, clientId, clientSecret, statusClientMock.Object), environmentServiceMock.Object); using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); string dockerfile1Path = CreateDockerfile("1.0/repo1/os", tempFolderContext); Manifest manifest = CreateManifest( CreateRepo(repo1, CreateImage( new Platform[] { CreatePlatform(dockerfile1Path, new string[] { platformTag1 }) }, productVersion: "1.0")) ); ImageArtifactDetails imageArtifactDetails = new ImageArtifactDetails { Repos = { { new RepoData { Repo = repo1, Images = { new ImageData { Platforms = { CreatePlatform( PathHelper.NormalizePath(dockerfile1Path), simpleTags: new List <string> { platformTag1 }, digest: platformDigest1) } } } } } } }; command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.ImageInfoPath = Path.Combine(tempFolderContext.Path, "image-info.json"); command.Options.WaitTimeout = TimeSpan.FromMinutes(1); command.Options.ServicePrincipal.Tenant = tenant; command.Options.ServicePrincipal.ClientId = clientId; command.Options.ServicePrincipal.Secret = clientSecret; command.Options.MinimumQueueTime = baselineTime; command.Options.WaitTimeout = TimeSpan.FromMinutes(1); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); File.WriteAllText(command.Options.ImageInfoPath, JsonConvert.SerializeObject(imageArtifactDetails)); command.LoadManifest(); await command.ExecuteAsync(); statusClientMock.Verify(o => o.GetImageResultAsync(platformDigest1), Times.Exactly(3)); statusClientMock.Verify(o => o.GetImageResultDetailedAsync(platformDigest1, tag1aOnboardingRequestId), Times.Once); statusClientMock.Verify(o => o.GetImageResultDetailedAsync(platformDigest1, tag1bOnboardingRequestId), Times.Once); environmentServiceMock.Verify(o => o.Exit(1), Times.Once); }
public async Task WaitTimeout() { DateTime baselineTime = DateTime.Now; const string platformTag1 = "platformTag1"; const string repo1 = "repo1"; const string platformDigest1 = "platformDigest1"; Mock <IMcrStatusClient> statusClientMock = new Mock <IMcrStatusClient>(); statusClientMock .Setup(o => o.GetImageResultAsync(It.IsAny <string>())) .ReturnsAsync( new ImageResult { Digest = platformDigest1, Value = new List <ImageStatus> { new ImageStatus { Tag = platformTag1, TargetRepository = repo1, QueueTime = baselineTime.AddHours(1), OverallStatus = StageStatus.Processing } } }); const string tenant = "my tenant"; const string clientId = "my id"; const string clientSecret = "very secret"; Mock <IEnvironmentService> environmentServiceMock = new Mock <IEnvironmentService>(); WaitForMcrImageIngestionCommand command = new WaitForMcrImageIngestionCommand( Mock.Of <ILoggerService>(), CreateMcrStatusClientFactory(tenant, clientId, clientSecret, statusClientMock.Object), environmentServiceMock.Object); using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); string dockerfile1Path = CreateDockerfile("1.0/repo1/os", tempFolderContext); Manifest manifest = CreateManifest( CreateRepo(repo1, CreateImage( new Platform[] { CreatePlatform(dockerfile1Path, new string[] { platformTag1 }) }, productVersion: "1.0")) ); ImageArtifactDetails imageArtifactDetails = new ImageArtifactDetails { Repos = { { new RepoData { Repo = repo1, Images = { new ImageData { Platforms = { CreatePlatform( PathHelper.NormalizePath(dockerfile1Path), simpleTags: new List <string> { platformTag1 }, digest: platformDigest1) } } } } } } }; command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.ImageInfoPath = Path.Combine(tempFolderContext.Path, "image-info.json"); command.Options.WaitTimeout = TimeSpan.FromMinutes(1); command.Options.ServicePrincipal.Tenant = tenant; command.Options.ServicePrincipal.ClientId = clientId; command.Options.ServicePrincipal.Secret = clientSecret; command.Options.MinimumQueueTime = baselineTime; command.Options.WaitTimeout = TimeSpan.FromSeconds(3); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); File.WriteAllText(command.Options.ImageInfoPath, JsonConvert.SerializeObject(imageArtifactDetails)); command.LoadManifest(); await Assert.ThrowsAsync <TimeoutException>(() => command.ExecuteAsync()); }
public async Task SuccessfulPublish() { DateTime baselineTime = DateTime.Now; const string manifestDigest1 = "manifestDigest1"; const string sharedTag1 = "sharedTag1"; const string sharedTag2 = "sharedTag2"; const string platformTag1 = "platformTag1"; const string platformTag2 = "platformTag2"; const string platformTag3 = "platformTag3"; const string repo1 = "repo1"; const string repo2 = "repo2"; const string platformDigest1 = "platformDigest1"; const string platformDigest2 = "platformDigest2"; Mock <IMcrStatusClient> statusClientMock = new Mock <IMcrStatusClient>(); ImageStatus previousSharedTag1ImageStatus = new ImageStatus { Tag = sharedTag1, TargetRepository = repo1, QueueTime = baselineTime.AddHours(-1), OverallStatus = StageStatus.Succeeded }; ImageStatus sharedTag1ImageStatus = new ImageStatus { Tag = sharedTag1, TargetRepository = repo1, QueueTime = baselineTime.AddHours(1), OverallStatus = StageStatus.NotStarted }; ImageStatus sharedTag2ImageStatus = new ImageStatus { Tag = sharedTag2, TargetRepository = repo1, QueueTime = baselineTime, OverallStatus = StageStatus.Processing }; ImageStatus platformTag1ImageStatus = new ImageStatus { Tag = platformTag1, TargetRepository = repo1, QueueTime = baselineTime.AddHours(1), OverallStatus = StageStatus.Processing }; ImageStatus platformTag2ImageStatus = new ImageStatus { Tag = platformTag2, TargetRepository = repo1, QueueTime = baselineTime.AddHours(1), OverallStatus = StageStatus.Processing }; ImageStatus platformTag3ImageStatus = new ImageStatus { Tag = platformTag3, TargetRepository = repo2, QueueTime = baselineTime.AddSeconds(1), OverallStatus = StageStatus.Succeeded }; Dictionary <string, IEnumerator <ImageResult> > imageResultMapping = new Dictionary <string, IEnumerator <ImageResult> > { { manifestDigest1, new List <ImageResult> { new ImageResult { Digest = manifestDigest1, Value = new List <ImageStatus> { previousSharedTag1ImageStatus, sharedTag1ImageStatus, sharedTag2ImageStatus, } }, new ImageResult { Digest = manifestDigest1, Value = new List <ImageStatus> { previousSharedTag1ImageStatus, Clone(sharedTag1ImageStatus, StageStatus.Processing), sharedTag2ImageStatus, } }, new ImageResult { Digest = manifestDigest1, Value = new List <ImageStatus> { previousSharedTag1ImageStatus, Clone(sharedTag1ImageStatus, StageStatus.Succeeded), sharedTag2ImageStatus, } }, new ImageResult { Digest = manifestDigest1, Value = new List <ImageStatus> { previousSharedTag1ImageStatus, Clone(sharedTag1ImageStatus, StageStatus.Succeeded), Clone(sharedTag2ImageStatus, StageStatus.Succeeded), } } }.GetEnumerator() }, { platformDigest1, new List <ImageResult> { new ImageResult { Digest = platformDigest1, Value = new List <ImageStatus> { platformTag1ImageStatus, platformTag2ImageStatus, } }, new ImageResult { Digest = platformDigest1, Value = new List <ImageStatus> { Clone(platformTag1ImageStatus, StageStatus.Succeeded), Clone(platformTag2ImageStatus, StageStatus.Succeeded), } } }.GetEnumerator() }, { platformDigest2, new List <ImageResult> { new ImageResult { Digest = platformDigest2, Value = new List <ImageStatus>() }, new ImageResult { Digest = platformDigest2, Value = new List <ImageStatus> { platformTag3ImageStatus } } }.GetEnumerator() } }; statusClientMock .Setup(o => o.GetImageResultAsync(It.IsAny <string>())) .ReturnsAsync((string digest) => { IEnumerator <ImageResult> enumerator = imageResultMapping[digest]; if (enumerator.MoveNext()) { return(enumerator.Current); } return(null); }); const string tenant = "my tenant"; const string clientId = "my id"; const string clientSecret = "very secret"; Mock <IEnvironmentService> environmentServiceMock = new Mock <IEnvironmentService>(); WaitForMcrImageIngestionCommand command = new WaitForMcrImageIngestionCommand( Mock.Of <ILoggerService>(), CreateMcrStatusClientFactory(tenant, clientId, clientSecret, statusClientMock.Object), environmentServiceMock.Object); using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); string dockerfile1Path = CreateDockerfile("1.0/repo1/os", tempFolderContext); string dockerfile2Path = CreateDockerfile("1.0/repo2/os", tempFolderContext); Manifest manifest = CreateManifest( CreateRepo(repo1, CreateImage( new Platform[] { CreatePlatform(dockerfile1Path, new string[] { platformTag1, platformTag2 }) }, productVersion: "1.0")), CreateRepo(repo2, CreateImage( new Platform[] { CreatePlatform(dockerfile2Path, new string[] { platformTag3 }) }, productVersion: "1.0")) ); ImageArtifactDetails imageArtifactDetails = new ImageArtifactDetails { Repos = { { new RepoData { Repo = repo1, Images = { new ImageData { Manifest = new ManifestData { Digest = manifestDigest1, SharedTags = new List <string> { sharedTag1, sharedTag2 } }, Platforms = { CreatePlatform( PathHelper.NormalizePath(dockerfile1Path), simpleTags: new List <string> { platformTag1, platformTag2 }, digest: platformDigest1) } } } } }, { new RepoData { Repo = repo2, Images = { new ImageData { Platforms = { CreatePlatform( PathHelper.NormalizePath(dockerfile2Path), simpleTags: new List <string> { platformTag3 }, digest: platformDigest2) } } } } } } }; command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.ImageInfoPath = Path.Combine(tempFolderContext.Path, "image-info.json"); command.Options.WaitTimeout = TimeSpan.FromMinutes(1); command.Options.ServicePrincipal.Tenant = tenant; command.Options.ServicePrincipal.ClientId = clientId; command.Options.ServicePrincipal.Secret = clientSecret; command.Options.MinimumQueueTime = baselineTime; command.Options.WaitTimeout = TimeSpan.FromMinutes(1); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); File.WriteAllText(command.Options.ImageInfoPath, JsonConvert.SerializeObject(imageArtifactDetails)); command.LoadManifest(); await command.ExecuteAsync(); statusClientMock.Verify(o => o.GetImageResultAsync(manifestDigest1), Times.Exactly(4)); statusClientMock.Verify(o => o.GetImageResultAsync(platformDigest1), Times.Exactly(2)); statusClientMock.Verify(o => o.GetImageResultAsync(platformDigest2), Times.Exactly(2)); environmentServiceMock.Verify(o => o.Exit(It.IsAny <int>()), Times.Never); }