Пример #1
0
        public void SetStepTarget(Pipelines.StepTarget target)
        {
            // Enforce command restriction if set for the step target
            var commandManager = HostContext.GetService <IWorkerCommandManager>();

            if (string.Equals(WellKnownStepTargetStrings.Restricted, target?.Commands, StringComparison.OrdinalIgnoreCase))
            {
                commandManager.SetCommandRestrictionPolicy(new AttributeBasedWorkerCommandRestrictionPolicy());
            }
            else
            {
                commandManager.SetCommandRestrictionPolicy(new UnrestricedWorkerCommandRestrictionPolicy());
            }

            // When step targets are set, we need to take over control for translating paths
            // from the job execution context
            Variables.StringTranslator = TranslatePathForStepTarget;

            if (string.Equals(WellKnownStepTargetStrings.Host, target?.Target, StringComparison.OrdinalIgnoreCase))
            {
                _currentStepTarget = new HostInfo();
            }
            else
            {
                _currentStepTarget = Containers.FirstOrDefault(x => string.Equals(x.ContainerName, target?.Target, StringComparison.OrdinalIgnoreCase));
            }
        }
Пример #2
0
        public async Task SetStepTarget()
        {
            using (TestHostContext hc = CreateTestContext())
            {
                var stepTarget = new Pipelines.StepTarget {
                    Target = "container"
                };
                var step = CreateStep(TaskResult.Succeeded, ExpressionManager.Succeeded);
                step.Setup(x => x.Target).Returns(stepTarget);

                // Override step context
                var stepContext = new Mock <IExecutionContext>();
                stepContext.SetupAllProperties();
                stepContext.Setup(x => x.Variables).Returns(_variables);
                stepContext.Setup(x => x.Complete(It.IsAny <TaskResult?>(), It.IsAny <string>(), It.IsAny <string>()))
                .Callback((TaskResult? r, string currentOperation, string resultCode) =>
                {
                    if (r != null)
                    {
                        stepContext.Object.Result = r;
                    }
                });
                step.Setup(x => x.ExecutionContext).Returns(stepContext.Object);

                // Act.
                await _stepsRunner.RunAsync(
                    jobContext : _ec.Object,
                    steps : new[] { step.Object });

                // Assert.
                stepContext.Verify(x => x.SetStepTarget(stepTarget), Times.Once);
            }
        }
Пример #3
0
        public void SetStepTarget(Pipelines.StepTarget target)
        {
            // When step targets are set, we need to take over control for translating paths
            // from the job execution context
            Variables.StringTranslator = TranslatePathForStepTarget;

            if (string.Equals(WellKnownStepTargetStrings.Host, target?.Target, StringComparison.OrdinalIgnoreCase))
            {
                _currentStepTarget = new HostInfo();
            }
            else
            {
                _currentStepTarget = Containers.FirstOrDefault(x => string.Equals(x.ContainerName, target?.Target, StringComparison.OrdinalIgnoreCase));
            }
        }