public async Task WhenInstanceCreated_ThenListInstanceEventsAsyncCanFeedHistorySetBuilder(
            [LinuxInstance] InstanceRequest testInstance)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var loggingService = new LoggingService(new BaseClientService.Initializer
            {
                HttpClientInitializer = Defaults.GetCredential()
            });

            var computeService = new ComputeService(new BaseClientService.Initializer
            {
                HttpClientInitializer = Defaults.GetCredential()
            });

            var instanceBuilder = new InstanceSetHistoryBuilder(
                DateTime.UtcNow.AddDays(-7),
                DateTime.UtcNow);
            await instanceBuilder.AddExistingInstances(
                computeService.Instances,
                computeService.Disks,
                Defaults.ProjectId);

            await loggingService.Entries.ListInstanceEventsAsync(
                new[] { Defaults.ProjectId },
                instanceBuilder.StartDate,
                instanceBuilder);

            var set = instanceBuilder.Build();
            var testInstanceHistory = set.Instances.FirstOrDefault(i => i.Reference == instanceRef);

            Assert.IsNotNull(testInstanceHistory, "Instance found in history");
        }
예제 #2
0
        public async Task WhenInstanceCreated_ThenListInstanceEventsAsyncCanFeedHistorySetBuilder(
            [LinuxInstance] InstanceRequest testInstance)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var instanceBuilder = new InstanceSetHistoryBuilder(
                DateTime.UtcNow.AddDays(-7),
                DateTime.UtcNow);

            var computeAdapter = new ComputeEngineAdapter(Defaults.GetCredential());

            instanceBuilder.AddExistingInstances(
                await computeAdapter.ListInstancesAsync(Defaults.ProjectId, CancellationToken.None),
                await computeAdapter.ListDisksAsync(Defaults.ProjectId, CancellationToken.None),
                Defaults.ProjectId);

            var adapter = new AuditLogAdapter(Defaults.GetCredential());

            await adapter.ListInstanceEventsAsync(
                new[] { Defaults.ProjectId },
                null,  // all zones.
                null,  // all instances.
                instanceBuilder.StartDate,
                instanceBuilder,
                CancellationToken.None);

            var set = instanceBuilder.Build();
            var testInstanceHistory = set.Instances.FirstOrDefault(i => i.Reference == instanceRef);

            Assert.IsNotNull(testInstanceHistory, "Instance found in history");
        }
        public async Task WhenInstanceCreated_ThenProcessInstanceEventsAsyncCanFeedHistorySetBuilder(
            [LinuxInstance] ResourceTask <InstanceLocator> testInstance,
            [Credential(Roles = new[] {
            PredefinedRole.ComputeViewer,
            PredefinedRole.LogsViewer
        })] ResourceTask <ICredential> credential)
        {
            await testInstance;
            var   instanceRef = await testInstance;

            var instanceBuilder = new InstanceSetHistoryBuilder(
                DateTime.UtcNow.AddDays(-7),
                DateTime.UtcNow);

            var computeAdapter = new ComputeEngineAdapter(await credential);

            instanceBuilder.AddExistingInstances(
                await computeAdapter.ListInstancesAsync(TestProject.ProjectId, CancellationToken.None),
                await computeAdapter.ListNodesAsync(TestProject.ProjectId, CancellationToken.None),
                await computeAdapter.ListDisksAsync(TestProject.ProjectId, CancellationToken.None),
                TestProject.ProjectId);

            var adapter = new AuditLogAdapter(await credential);

            await adapter.ProcessInstanceEventsAsync(
                new[] { TestProject.ProjectId },
                null,  // all zones.
                null,  // all instances.
                instanceBuilder.StartDate,
                instanceBuilder,
                CancellationToken.None);

            var set = instanceBuilder.Build();
            var testInstanceHistory = set.Instances.FirstOrDefault(i => i.Reference == instanceRef);

            Assert.IsNotNull(testInstanceHistory, "Instance found in history");
        }