Esempio n. 1
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 WhenUserNotInRole_ThenListDisksAsyncThrowsResourceAccessDeniedException(
            [Credential(Role = PredefinedRole.IapTunnelUser)] ResourceTask <ICredential> credential)
        {
            var adapter = new ComputeEngineAdapter(await credential);

            AssertEx.ThrowsAggregateException <ResourceAccessDeniedException>(
                () => adapter.ListDisksAsync(
                    TestProject.ProjectId,
                    CancellationToken.None).Wait());
        }
        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");
        }