Skip to content

Commit

Permalink
Add support for Kong 0.10 (#2)
Browse files Browse the repository at this point in the history
* Add support for Kong 0.10

Added support for Kong 0.10. This included changes to api
validation to support backwards incompatible field changes. Also
added a package config `kongVersion`. This is currently defaulted
to `0.9` but can be set by`npm config kingkong:kongVersion 0.10`
to test against other Kong versions. Tests are configured to use
`kongVersion` as part of the spec file name.

* Add more Kong 0.10 supported api fields

* Remove 0.9 compatibility
  • Loading branch information
brothhaar authored and esatterwhite committed Apr 11, 2017
1 parent 80b7d16 commit 1ec2193
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
Empty file modified bin/cli.js 100644 → 100755
Empty file.
15 changes: 11 additions & 4 deletions lib/validation/api.js
Expand Up @@ -13,10 +13,17 @@ var joi = require('joi')

module.exports = joi.object({
name: joi.string()
, request_path: joi.string().optional()
, request_host: joi.string().when('request_path',{is:joi.empty(), then:joi.optional(), otherwise:joi.optional() })
, strip_request_path: joi.boolean().default( false )
, preserve_host: joi.boolean().default( false ).description('Preserves the original Host header sent by the client, instead of replacing it with the hostname of the upstream_url')
, hosts: joi.array().unique()
, uris: joi.array().items(joi.string().optional())
, methods: joi.array().unique()
, upstream_url: joi.string().required().description("The base target URL that points to your API server, this URL will be used for proxying requests. For example, https://mockbin.com")
, strip_uri: joi.boolean()
, preserve_host: joi.boolean().description('Preserves the original Host header sent by the client, instead of replacing it with the hostname of the upstream_url')
, retries: joi.number()
, upstream_connect_timeout: joi.number()
, upstream_read_timeout: joi.number()
, upstream_send_timeout: joi.number()
, https_only: joi.boolean()
, http_if_terminated: joi.boolean()
, plugins: joi.object().unknown().optional()
});
2 changes: 1 addition & 1 deletion script/test.js
Expand Up @@ -31,7 +31,7 @@ var child_process = require('child_process') // child proces for s
;

root = path.resolve(__dirname)
root = path.join(root, "../**/test/*.spec.js" )
root = path.join(root, `../**/test/*.spec.js` )
// inject some test vars into the env
env.MOCHA_COLORS = 1

Expand Down
43 changes: 21 additions & 22 deletions test/king.spec.js
Expand Up @@ -75,9 +75,14 @@ describe('King', function(){
apis:[{
name:'__test',
upstream_url:'http://localhost:9000',
request_path:'/test',
strip_request_path:true,
request_path:'/test'
uris:['/test'],
strip_uri:true,
retries: 7,
upstream_connect_timeout: 90000,
upstream_read_timeout: 90000,
upstream_send_timeout: 90000,
http_if_terminated: false,
https_only: false
}]
,onSync: function(){
done();
Expand Down Expand Up @@ -106,9 +111,8 @@ describe('King', function(){
apis:[{
name:'__test',
upstream_url:'http://localhost:9000',
request_path:'/test',
strip_request_path:true,
request_path:'/test',
uris:['/test'],
strip_uri:true,
plugins:{
'http-log':{
config:{
Expand All @@ -134,9 +138,8 @@ describe('King', function(){
apis:[{
name:'__test',
upstream_url:'localhost:9000',
request_path:'/test',
strip_request_path:true,
request_path:'/test'
uris:['/test'],
strip_uri:true
}]
});
k.sync()
Expand All @@ -158,9 +161,8 @@ describe('King', function(){
apis:[{
name:'__test',
upstream_url:'http://localhost:9000',
request_path:'/test',
strip_request_path:true,
request_path:'/test',
uris:['/test'],
strip_uri:true,
plugins:{
'bad-plugin':{
config:{
Expand Down Expand Up @@ -190,9 +192,8 @@ describe('King', function(){
apis:[{
name:'__test',
upstream_url:'http://localhost:9000',
request_path:'/test',
strip_request_path:true,
request_path:'/test',
uris:['/test'],
strip_uri:true,
plugins:{
'http-log':{
configs:{
Expand Down Expand Up @@ -222,9 +223,8 @@ describe('King', function(){
apis:[{
name:'__test',
upstream_url:'http://localhost:9000',
request_path:'/test',
strip_request_path:true,
request_path:'/test',
uris:['/test'],
strip_uri:true,
plugins:{
'http-log':{
config:{
Expand Down Expand Up @@ -255,15 +255,14 @@ describe('King', function(){
apis:[{
name:'__test',
upstream_url:'http://localhost:9000',
request_path:'/test',
strip_request_path:false,
request_path:'/test'
uris:['/test'],
strip_uri:false
}]
,onSync:function(){
setTimeout(function(){
k2.request('get','apis','__test')
.then( function( data ){
assert.strictEqual(data.body.strip_request_path, false);
assert.strictEqual(data.body.strip_uri, false);
done();
})
.catch( done )
Expand Down

0 comments on commit 1ec2193

Please sign in to comment.