public void ShouldParseWorkflowRunStepWithExpression() { //Arrange var stepsResolver = A.Fake <IWorkflowStepResolver>(); var expectedSteps = new IWorkflowStep[] { new WorkflowRunStep { Name = "step-1", Command = "./output/${{ jeeves.inputs.exeName }}" } }; var expectedWorkflow = new Workflow(); expectedWorkflow.Stages = new Dictionary <string, WorkflowStage> { { "Build", new WorkflowStage { Steps = expectedSteps } } }; A.CallTo(() => stepsResolver.Resolve(A <IReadOnlyCollection <string> > .Ignored)).Returns(typeof(WorkflowRunStep)); var parser = new WorkflowParser(stepsResolver); //Act var workflow = parser.Parse(@" stages: Build: steps: - name: step-1 run: ./output/${{ jeeves.inputs.exeName }} "); //Assert workflow.Should().BeEquivalentTo(expectedWorkflow); }
public void ShouldParseWorkflowRunStepWithTimeout() { //Arrange var stepsResolver = A.Fake <IWorkflowStepResolver>(); var options = new WorkflowRunStepOptions { Timeout = 2400 }; var steps = new IWorkflowStep[] { new WorkflowRunStep { Name = "step-1", Command = "command-1", Options = options } }; var expectedWorkflow = new Workflow(); expectedWorkflow.Stages = new Dictionary <string, WorkflowStage> { { "Build", new WorkflowStage { Steps = steps } } }; A.CallTo(() => stepsResolver.Resolve(A <IReadOnlyCollection <string> > .Ignored)).Returns(typeof(WorkflowRunStep)); var parser = new WorkflowParser(stepsResolver); //Act var workflow = parser.Parse(@" stages: Build: steps: - name: step-1 run: command-1 with: timeout: 2400 "); //Assert workflow.Should().BeEquivalentTo(expectedWorkflow); }
public void Parse_Positive() { var actionWorkflow1 = new ActionWorkflow { Name = "workflow-1" }; var actionWorkflow2 = new ActionWorkflow { Name = "workflow-2" }; var deserializerMock = Mock.Create <IDeserializer>(); Mock.Arrange(() => deserializerMock.Deserialize <ActionWorkflow>( Arg.Matches <StreamReader>(r => Path.GetFileName((r.BaseStream as FileStream).Name) == _fixture.Files[0]))) .Returns(actionWorkflow1); Mock.Arrange(() => deserializerMock.Deserialize <ActionWorkflow>( Arg.Matches <StreamReader>(r => Path.GetFileName((r.BaseStream as FileStream).Name) == _fixture.Files[1]))) .Returns(actionWorkflow2); var deserializerFactoryMock = Mock.Create <IDeserializerFactory>(); Mock.Arrange(() => deserializerFactoryMock.Get()).Returns(deserializerMock); var parser = new WorkflowParser(deserializerFactoryMock); IEnumerable <WorkflowInfo> result = parser.Parse(_fixture.Files); Assert.Equal(2, result.Count()); WorkflowInfo workflowInfo = result.First(); Assert.Equal(_fixture.Files[0], workflowInfo.File.FilePath); Assert.Equal(actionWorkflow1, workflowInfo.Workflow); workflowInfo = result.Last(); Assert.Equal(_fixture.Files[1], workflowInfo.File.FilePath); Assert.Equal(actionWorkflow2, workflowInfo.Workflow); }
public void ShouldParseWorkflowRunStep() { //Arrange var stepsResolver = A.Fake <IWorkflowStepResolver>(); var expectedSteps = new IWorkflowStep[] { new WorkflowAssertStep { Name = "step-1", Assert = "assert-1" } }; var expectedWorkflow = new Workflow(); expectedWorkflow.Stages = new Dictionary <string, WorkflowStage> { { "Build", new WorkflowStage { Steps = expectedSteps } } }; A.CallTo(() => stepsResolver.Resolve(A <IReadOnlyCollection <string> > .Ignored)).Returns(typeof(WorkflowAssertStep)); var parser = new WorkflowParser(stepsResolver); //Act var workflow = parser.Parse(@" stages: Build: steps: - name: step-1 assert: assert-1 "); //Assert workflow.Should().BeEquivalentTo(expectedWorkflow); }
public void WorkflowStagesShouldBeNullIfStagesAreNotSpecified() { //Arrange var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse("stages: "); //Assert workflow.Stages.Should().BeNull(); }
public void WorkflowParametersShouldBeNullIfParametersAreNotSpecified() { //Arrange var yaml = $@"name: amazing"; var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse(yaml); //Assert workflow.Parameters.Should().BeNull(); }
public void WorkflowParametersShouldBeNullIfParametersAreEmpty() { //Arrange var yaml = $@"parameters: "; var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse(yaml); //Assert workflow.Parameters.Should().BeNull(); }
public void ShouldParseWorkflowHostType() { //Arrange var yaml = $"runs-on: windows-latest"; var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse(yaml); //Assert workflow.HostType.Should().Be("windows-latest"); }
public void ShouldParseWorkflowName(string name) { //Arrange var yaml = $"name: {name}"; var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse(yaml); //Assert workflow.Name.Should().Be(name); }
public void WorkflowParameterNameShouldBeEqualToKey() { //Arrange var yaml = @" parameters: exeName: description: 'Executable name' required: true"; var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse(yaml); //Assert workflow.Parameters["exeName"].Name.Should().Be("exeName"); }
public void ShouldParseEmptyWorkflowStages(int stagesNumber) { //Arrange var faker = new Faker(); var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); var expectedStages = Enumerable.Range(0, stagesNumber) .Select(unused => faker.GetUniqueRandomWord(1, 100)) .ToDictionary(id => id, id => new WorkflowStage { Steps = null }); //Act var workflow = parser.Parse(expectedStages.ToYaml()); //Assert workflow.Stages.Should().BeEquivalentTo(expectedStages); }
public void ShouldParseWorkflowParametersSpecifiedAsScalar() { //Arrange var parameter = new WorkflowParameter { Name = "SomeParameter" }; var expectedParameters = new Dictionary <string, WorkflowParameter> { { parameter.Name, parameter } }; var yaml = $@"parameters: {parameter.Name}"; var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse(yaml); //Assert workflow.Parameters.Should().BeEquivalentTo(expectedParameters); }
public void ShouldParseWorkflowStageSteps() { //Arrange var stepsResolver = A.Fake <IWorkflowStepResolver>(); var expectedSteps = new IWorkflowStep[] { new WorkflowRunStep { Name = "step-1", Command = "command-1" }, new WorkflowAssertStep { Name = "step-2", Assert = "assert-2" } }; var expectedWorkflow = new Workflow { Stages = new Dictionary <string, WorkflowStage> { { "Build", new WorkflowStage { Steps = expectedSteps } } } }; A.CallTo(() => stepsResolver.Resolve(A <IReadOnlyCollection <string> > .Ignored)).ReturnsLazily(args => { var properties = args.GetArgument <IReadOnlyCollection <string> >(0); return(properties !.Contains("run", StringComparer.OrdinalIgnoreCase) ? typeof(WorkflowRunStep) : typeof(WorkflowAssertStep)); }); var parser = new WorkflowParser(stepsResolver); //Act var workflow = parser.Parse(@" stages: Build: steps: - name: step-1 run: command-1 - name: step-2 assert: assert-2 "); //Assert workflow.Should().BeEquivalentTo(expectedWorkflow); }
public void ShouldParseWorkflowParametersSpecifiedAsSequence(int parametersNumber) { //Arrange var faker = new Faker(); var expectedParameters = Enumerable.Range(0, parametersNumber) .Select(unused => faker.GetUniqueRandomWord(1, 100)) .Select(parameterName => new WorkflowParameter { Name = parameterName }) .ToDictionary(parameter => parameter.Name); var yaml = $@"parameters: [{string.Join(",", expectedParameters.Values.Select(p => p.Name))}]"; var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); //Act var workflow = parser.Parse(yaml); //Assert workflow.Parameters.Should().BeEquivalentTo(expectedParameters); }
public void ShouldParseWorkflowParametersSpecifiedAsMapping(int parametersNumber) { //Arrange var faker = new Faker(); var parser = new WorkflowParser(A.Dummy <IWorkflowStepResolver>()); var expectedParameters = Enumerable.Range(0, parametersNumber) .Select(unused => faker.GetUniqueRandomWord(1, 100)) .Select(parameterName => new WorkflowParameter { Name = faker.GetUniqueRandomWord(1, 100), Description = faker.Lorem.Sentence(), Default = faker.Lorem.Sentence(), Required = faker.Random.Bool() }) .ToDictionary(parameter => parameter.Name); //Act var workflow = parser.Parse(expectedParameters.ToYaml()); //Assert workflow.Parameters.Should().BeEquivalentTo(expectedParameters); }