public void TestGenerateOptionalResource() { var prompter = new TestPrompter(); var generator = new Generator(prompter); prompter.AddResponse("bing.com"); prompter.AddResponse("to"); prompter.AddResponse("n"); prompter.AddResponse("n"); prompter.AddResponse("LossAction"); prompter.AddResponse("0.5"); prompter.AddResponse("y"); prompter.AddResponse("0.2"); prompter.AddResponse("n"); NetworkChaos resource = generator.GenerateResource <NetworkChaos>(); resource.ExternalTargets.Should().Equal(new List <string> { "bing.com" }); resource.Action.Should().BeAssignableTo <NetworkChaos.LossAction>(); var loss = resource.Action as NetworkChaos.LossAction; loss.Loss.Should().Be(0.5); loss.Correlation.Should().Be(0.2); }
public void TestGenerateResource() { var prompter = new TestPrompter(); var generator = new Generator(prompter); // Test resource name selection prompter.AddResponse("bash -c sleep 3600"); prompter.AddResponse("true"); var resource = generator.GenerateResource <JobWithoutAzureResourceDeployment>(); resource.Command.Should().Equal(new List <string> { "bash", "-c", "sleep", "3600" }); resource.ChaosEnabled.Should().Be(true); }
public void TestMultipleChoiceWithIntSelection() { var prompter = new TestPrompter(); var generator = new Generator(prompter); prompter.AddResponse("TestStressPackage"); prompter.AddResponse("TestStressNamespace"); prompter.AddResponse("0"); prompter.AddResponse("bash -c sleep 3600"); prompter.AddResponse("true"); prompter.AddResponse("n"); var package = generator.GenerateResource <StressTestPackage>(); package.Resources.Count.Should().Be(1); var job = package.Resources[0] as JobWithoutAzureResourceDeployment; job.Name.Should().Be("TestStressPackage"); job.Command.Should().Equal(new List <string> { "bash", "-c", "sleep", "3600" }); job.ChaosEnabled.Should().Be(true); }
public void TestGenerateNestedResources() { var prompter = new TestPrompter(); var generator = new Generator(prompter); prompter.AddResponse("TestStressPackage"); prompter.AddResponse("TestStressNamespace"); prompter.AddResponse(nameof(NetworkChaos)); prompter.AddResponse("bing.com"); prompter.AddResponse("to"); prompter.AddResponse("n"); prompter.AddResponse("n"); prompter.AddResponse("DelayAction"); prompter.AddResponse("50ms"); prompter.AddResponse("n"); prompter.AddResponse("n"); prompter.AddResponse("y"); prompter.AddResponse("2"); prompter.AddResponse("0.5"); prompter.AddResponse("n"); prompter.AddResponse("n"); var package = generator.GenerateResource <StressTestPackage>(); var chaos = package.Resources[0] as NetworkChaos; chaos.Name.Should().Be("TestStressPackage"); chaos.ExternalTargets.Should().Equal(new List <string> { "bing.com" }); chaos.Action.Should().BeAssignableTo <NetworkChaos.DelayAction>(); var delay = chaos.Action as NetworkChaos.DelayAction; delay.Latency.Should().Be("50ms"); delay.Correlation.Should().BeNull(); delay.Jitter.Should().BeNull(); delay.Reorder.Should().BeAssignableTo <NetworkChaos.ReorderSpec>(); delay.Reorder.Gap.Should().Be(2); delay.Reorder.Reorder.Should().Be(0.5); delay.Reorder.Correlation.Should().BeNull(); }
public void TestGeneratePackage() { var prompter = new TestPrompter(); var generator = new Generator(prompter); prompter.AddResponse("TestStressPackage"); prompter.AddResponse("TestStressNamespace"); prompter.AddResponse(nameof(JobWithoutAzureResourceDeployment)); // Command prompter.AddResponse("bash -c sleep 3600"); // Enable chaos prompter.AddResponse("true"); // Another resource prompter.AddResponse("y"); prompter.AddResponse(nameof(NetworkChaos)); // External target prompter.AddResponse("bing.com"); // Packet Direction prompter.AddResponse("to"); // Schedule prompter.AddResponse("y"); prompter.AddResponse("@every 30s"); // Duration prompter.AddResponse("y"); prompter.AddResponse("12s"); // Network Action Type prompter.AddResponse("LossAction"); prompter.AddResponse("0.5"); prompter.AddResponse("n"); prompter.AddResponse("n"); var package = generator.GenerateResource <StressTestPackage>(); package.Resources.Count.Should().Be(2); package.Name.Should().Be("TestStressPackage"); package.Namespace.Should().Be("TestStressNamespace"); var job = package.Resources[0] as JobWithoutAzureResourceDeployment; job.Name.Should().Be("TestStressPackage"); job.Command.Should().Equal(new List <string> { "bash", "-c", "sleep", "3600" }); job.ChaosEnabled.Should().Be(true); var chaos = package.Resources[1] as NetworkChaos; chaos.Name.Should().Be("TestStressPackage"); chaos.ExternalTargets.Should().Equal(new List <string> { "bing.com" }); chaos.Action.Should().BeAssignableTo <NetworkChaos.LossAction>(); var loss = chaos.Action as NetworkChaos.LossAction; loss.Loss.Should().Be(0.5); loss.Correlation.Should().BeNull(); }
public void TestGenerateInvalidMultipleChoiceRetry() { var prompter = new TestPrompter(); var generator = new Generator(prompter); prompter.AddResponse("TestStressPackage"); prompter.AddResponse("TestStressNamespace"); prompter.AddResponse("invalid1"); prompter.AddResponse("invalid2"); prompter.AddResponse("999"); prompter.AddResponse("-1"); prompter.AddResponse(nameof(JobWithoutAzureResourceDeployment)); prompter.AddResponse("bash -c sleep 3600"); prompter.AddResponse("invalidBool1"); prompter.AddResponse("invalidBool2"); prompter.AddResponse("true"); prompter.AddResponse("invalidOptional1"); prompter.AddResponse("n"); var package = generator.GenerateResource <StressTestPackage>(); package.Resources.Count.Should().Be(1); package.Name.Should().Be("TestStressPackage"); package.Namespace.Should().Be("TestStressNamespace"); var job = package.Resources[0] as JobWithoutAzureResourceDeployment; job.Name.Should().Be("TestStressPackage"); job.Command.Should().Equal(new List <string> { "bash", "-c", "sleep", "3600" }); job.ChaosEnabled.Should().Be(true); }