コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        private static KongPlugin CreateHttpLogPlugin(string httpEndpoint)
        {
            var plugin = new KongPlugin
            {
                Name   = "http-log",
                Config = new Dictionary <string, object>
                {
                    { "http_endpoint", httpEndpoint }
                }
            };

            return(plugin);
        }
コード例 #6
0
ファイル: TestPlugins.cs プロジェクト: justeat/kongverge
        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);
        }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
        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;
            }
        }
コード例 #9
0
ファイル: TestPlugins.cs プロジェクト: justeat/kongverge
 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;
コード例 #10
0
ファイル: TestPlugins.cs プロジェクト: justeat/kongverge
 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;
コード例 #11
0
ファイル: TestPlugins.cs プロジェクト: justeat/kongverge
 public static bool IsTheSameAs(this KongPlugin kongPlugin, KongPlugin expectedKongPlugin) =>
 ReferenceEquals(kongPlugin, expectedKongPlugin);
コード例 #12
0
        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)));
        }
コード例 #13
0
 public Task PutPlugin(KongPlugin plugin) => PutKongObject("/plugins", plugin);
コード例 #14
0
 public Task PutPlugin(KongPlugin plugin) => Task.CompletedTask;
コード例 #15
0
        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));
        }
コード例 #16
0
 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);
 }
コード例 #17
0
 public Task UpsertPlugin(KongPlugin plugin) => Task.CompletedTask;