public void Scenario8() { KongPlugin plugin = null; this.Given(() => plugin = Fixture.Create <KongPlugin>(), "A kong plugin") .And(s => s.KongRespondsCorrectly(HttpMethod.Delete, $"/plugins/{plugin.Id}"), KongRespondsCorrectlyToMethodAtPathTextTemplate) .When(async() => await Subject.DeletePlugin(plugin.Id), Invoking(nameof(KongAdminWriter.DeletePlugin))) .Then("it succeeds") .BDDfy(); }
public void Scenario6() { KongPlugin plugin = null; this.Given(() => plugin = Fixture.Build <KongPlugin>().Without(x => x.Id).Create(), "A new plugin") .And(s => s.KongRespondsCorrectly <KongService>(HttpMethod.Put, "/plugins", plugin.ToJsonStringContent(), x => x.WithIdAndCreatedAt()), KongRespondsCorrectlyToMethodAtPathTextTemplate) .When(async() => await Subject.UpsertPlugin(plugin), Invoking(nameof(KongAdminWriter.UpsertPlugin))) .Then(() => plugin.Id.Should().NotBeNullOrWhiteSpace(), "the Id is set") .BDDfy(); }
public void Scenario7() { KongPlugin plugin = null; this.Given(() => plugin = Fixture.Create <KongPlugin>(), "A kong plugin") .And(s => s.KongRespondsCorrectly <KongPlugin>(HttpMethod.Put, $"/plugins/{plugin.Id}", plugin.ToJsonStringContent()), KongRespondsCorrectlyToMethodAtPathTextTemplate) .When(async() => await Subject.PutPlugin(plugin), Invoking(nameof(KongAdminWriter.PutPlugin))) .Then("it succeeds") .BDDfy(); }
public async Task UpsertPlugin(KongPlugin plugin) { var content = plugin.ToJsonStringContent(); var response = await HttpClient.PutAsync("/plugins", content); var responseBody = await response.Content.ReadAsStringAsync(); var updated = JsonConvert.DeserializeObject <KongPlugin>(responseBody); plugin.Id = updated.Id; }
private static KongPlugin CreateHttpLogPlugin(string httpEndpoint) { var plugin = new KongPlugin { Name = "http-log", Config = new Dictionary <string, object> { { "http_endpoint", httpEndpoint } } }; return(plugin); }
public static KongPlugin AsTarget(this KongPlugin kongPlugin, bool modified = false) { var target = kongPlugin.Clone(); if (modified) { if (target.Config.HasValues) { target.Config[0] = Guid.NewGuid().ToString(); } else { target.Config.Add(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); } } return(target); }
public async Task UpsertPlugin(KongPlugin plugin) { Log.Information(string.IsNullOrWhiteSpace(plugin.Id) ? $"Adding plugin {plugin}" : $"Updating plugin {plugin}"); var content = new StringContent(JsonConvert.SerializeObject(plugin)); try { var response = await _httpClient.PutAsync("/plugins", content); var updated = await response.Content.ReadAsAsync <KongPlugin>(); plugin.Id = updated.Id; } catch (Exception e) { Log.Error(e, e.Message); throw; } }
public async Task UpsertPlugin(KongPlugin plugin) { Log.Information(string.IsNullOrWhiteSpace(plugin.Id) ? $"Adding plugin {plugin.Name}" : $"Updating plugin {plugin.Name}"); var content = plugin.ToJsonStringContent(); try { var response = await HttpClient.PutAsync("/plugins", content); var responseBody = await response.Content.ReadAsStringAsync(); var updated = JsonConvert.DeserializeObject <KongPlugin>(responseBody); plugin.Id = updated.Id; } catch (Exception e) { Log.Error(e, e.Message); throw; } }
public static bool CorrespondsToExistingPlugin(this KongPlugin kongPlugin, KongPlugin existingKongPlugin) => kongPlugin.Id == existingKongPlugin.Id && !string.IsNullOrWhiteSpace(kongPlugin.Id) && kongPlugin.CreatedAt == existingKongPlugin.CreatedAt && kongPlugin.UpdatedAt == existingKongPlugin.UpdatedAt;
public static bool CorrespondsToKongRoute(this KongPlugin kongPlugin, KongRoute kongRoute) => kongPlugin.Route?.Id == kongRoute.Id && !string.IsNullOrWhiteSpace(kongPlugin.Route?.Id) && kongPlugin.Consumer?.Id == null && kongPlugin.Service?.Id == null;
public static bool IsTheSameAs(this KongPlugin kongPlugin, KongPlugin expectedKongPlugin) => ReferenceEquals(kongPlugin, expectedKongPlugin);
protected ValidatableObjectSteps() { var examplePluginSchema = new KongPluginSchema { Fields = new Dictionary <string, FieldDefinition> { { "field1", new FieldDefinition { Type = "number", Default = JToken.FromObject(0) } }, { "field2", new FieldDefinition { Type = "string" } }, { "field3", new FieldDefinition { Type = "table", Schema = new KongPluginSchema { Fields = new Dictionary <string, FieldDefinition> { { "field1", new FieldDefinition { Type = "boolean" } }, { "field2", new FieldDefinition { Type = "string", Default = JToken.FromObject(this.Create <string>()) } } } } } } } }; ExamplePlugin = new KongPlugin { Name = "plugin1", Config = JObject.FromObject(new { field1 = 1, field2 = this.Create <string>(), field3 = new { field1 = this.Create <bool>(), field2 = this.Create <string>() } }) }; ExamplePluginWithMissingDefaultConfigFields = ExamplePlugin.Clone(); ExamplePluginWithMissingDefaultConfigFields.Config.Remove("field1"); ((JObject)ExamplePluginWithMissingDefaultConfigFields.Config.SelectToken("field3")).Remove("field2"); ExamplePluginWithOneInvalidConfigField = ExamplePlugin.Clone(); ExamplePluginWithOneInvalidConfigField.Config.Remove("field3"); ExamplePluginWithOneInvalidConfigField.Config.Add("field3", JToken.FromObject(this.Create <string>())); ExamplePluginWithTwoUnknownConfigFields = ExamplePlugin.Clone(); ExamplePluginWithTwoUnknownConfigFields.Config.Add(this.Create <string>(), JToken.FromObject(1)); ((JObject)ExamplePluginWithTwoUnknownConfigFields.Config.SelectToken("field3")).Add(this.Create <string>(), JToken.FromObject(this.Create <bool>())); AvailablePlugins.Add(ExamplePlugin.Name, new AsyncLazy <KongPluginSchema>(() => Task.FromResult(examplePluginSchema))); }
public Task PutPlugin(KongPlugin plugin) => PutKongObject("/plugins", plugin);
public Task PutPlugin(KongPlugin plugin) => Task.CompletedTask;
public static int Main(string[] args) { //Ensure we definitely remove that plugin, even if we crash AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; Console.CancelKeyPress += CancelHandler; var app = new CommandLineApplication { Name = "KongConfigurationValidation", Description = "Kong configuration validation." }; app.HelpOption("-?|-h|--help"); var kongHostOption = app.Option("-H|--host <KongHostname>", "Specify folder containing tests", CommandOptionType.SingleValue); var testsFolderOption = app.Option("-t|--testsFolder <testsFolder>", "Specify folder containing tests", CommandOptionType.SingleValue); var portOption = app.Option("-p|--port <HttpLogPort>", "Specify local logging listening port", CommandOptionType.SingleValue); app.OnExecute(async() => { var services = new ServiceCollection(); var testTracker = new TestTracker(); var startup = new Startup(testTracker); startup.ConfigureServices(services); var serviceProvider = services.BuildServiceProvider(); _testHelper = serviceProvider.GetService <ITestHelper>(); _kongAdminClient = serviceProvider.GetService <KongAdminClient>(); var configuration = serviceProvider.GetService <IOptions <Settings> >().Value; if (kongHostOption.HasValue()) { configuration.KongHost = kongHostOption.Value(); } else if (string.IsNullOrWhiteSpace(configuration.KongHost)) { throw new Exception("Kong hostname is not specified."); } if (portOption.HasValue()) { configuration.HttpLogPort = int.Parse(portOption.Value()); } if (testsFolderOption.HasValue()) { configuration.TestsFolder = testsFolderOption.Value(); } //Setup HTTP Logging Plugin var localIp = GetMostLikelyIpAddress().ToString(); var httpEndpoint = $"http://{localIp}:{configuration.HttpLogPort}"; Log.Information($"Adding HTTP Logging Plugin with url: {httpEndpoint}"); _httpLogPlugin = CreateHttpLogPlugin(httpEndpoint); await _kongAdminClient.UpsertPlugin(_httpLogPlugin); await Task.Delay(5000); //Start Logging WebServer BuildWebHost(args, testTracker, configuration.HttpLogPort).Start(); await WaitForWebServer(configuration.HttpLogPort); _testHelper.PopulateTests(); await _testHelper.RunTests(); await _testHelper.Validate(); #if DEBUG Console.WriteLine("Press any key to continue"); Console.ReadKey(); #endif return(0); }); return(app.Execute(args)); }
public Task UpsertPlugin(KongPlugin plugin) { Log.Information(string.IsNullOrWhiteSpace(plugin.Id) ? $"Adding plugin {plugin.Name}" : $"Updating plugin {plugin.Name}"); plugin.Id = plugin.Id ?? Guid.NewGuid().ToString(); return(Task.CompletedTask); }
public Task UpsertPlugin(KongPlugin plugin) => Task.CompletedTask;