'use strict';

const testing = require('testing');
const Koa = require('koa');
const koaRouter = require('koa-router');
const rq = require('request-promise');

module.exports.test = callback => {
	let tests = {};
	let routesTest = require('../app/routes/koas-router');
	let controllerTest = require('../app/controllers/controller');
	let Koax = require('../app/action/action');
	let Koas = require('../index');
	//koas-router 测试
	tests.routes = callback =>{
		let koasRoutes = new routesTest(true);
		koasRoutes.map = 1;//对set map()进行测试
		koasRoutes.jsonMap = 1;//对set jsonMap()进行测试
		testing.verify(Array.isArray(koasRoutes.map),'koasRoutes.map must be an Array',callback);
		testing.verify(typeof koasRoutes.jsonMap === 'object','koasRoutes.jsonMap must be an Object',callback);
		console.log(koasRoutes.jsonMap,koasRoutes.map)//测试的时候看结构用
		koasRoutes.deleteRouter('list','listtest1');
		let testMapDel = () => {
			for(let i = 0;i < koasRoutes.map.length;i++){
				if(koasRoutes.map[i] =='')
					return true
			}
			return false;
		}
		testing.verify(koasRoutes.jsonMap.list.listtest1.status==0,'delete failed ,please check deleteRouter',callback);
		testing.verify(testMapDel(),'delete failed ,please check deleteRouter',callback)
		koasRoutes.addRouter('list','listtest1');
		let testMapAdd = () => {
			for(let i = 0;i < koasRoutes.map.length;i++){
				if(koasRoutes.map[i] =='')
					return false
			}
			return true;
		}
		testing.verify(koasRoutes.jsonMap.list.listtest1.status==1,'add failed ,please check addRouter',callback);
		testing.verify(testMapAdd(),'add failed ,please check addRouter',callback)
		testing.success(callback);
	}
	tests.controller = callback => {
		let koasController = new controllerTest(true);
		koasController.jsonMap = 1;//对set jsonMap()进行测试
		testing.verify(typeof koasController.jsonMap === 'object','koasController.map must be an Object',callback)
		console.log(koasController.jsonMap);
		testing.success(callback);
		let koasSlot = koasController.slot('movie','movietest1')
		testing.verify((typeof koasSlot).match('function'),'slot must return a function or async function',callback)
	}
	tests.Koas = async callback => {
		let app = new Koas(true);
		let koax = new Koax();
		let testkoa = new Koa();
		let testrouter = new koaRouter();
		testrouter.get('/testkoax1',(ctx,next)=>{
			ctx.body = require('./json/testKoax1');
			ctx.status = 200;
		});
		testrouter.post('/testkoax2',(ctx,next)=>{
			ctx.body = require('./json/testKoax2');
			ctx.status = 200;
		});
		testkoa.use(testrouter.routes());
		let testserver = testkoa.listen('8012');
		koax.setName('testKoax1').request({
			uri:'http://localhost:8012/testkoax1',
			method:'GET'
		});
		koax.setName('testKoax2').cached().request({
			uri:'http://localhost:8012/testKoax2',
			method:'POST'
		});
		app.use(koax.middleware());
		let server = app.listen('8011');
		let httprequest = await rq('http://localhost:8011/list');
		testing.verify(httprequest,callback);
		testserver.close((error) => {
			testing.check(error, 'Could not stop server', callback);
		});
		// server.close((error) => {
		// 	testing.check(error, 'Could not stop server', callback);
		// 	testing.success(callback);
		// });
		testing.success(callback);
	}
	testing.run(tests, 1000, callback);
}
exports.test(testing.show);
@@ -3059,16 +3059,98 @@
 ;%0A%09%09%7D);%0A
+%09%09/*daily build %E9%9C%80%E8%A6%81%E6%94%B9%E4%B8%80%E4%B8%8B%E6%B3%A8%E9%87%8A%E5%95%8A%EF%BC%8C%E5%88%ABtmd%E5%BF%98%E4%BA%86%E3%80%82%E3%80%82%E3%80%82%E8%A6%81%E4%B8%8D%E7%84%B6%E5%8F%88failing%E4%BA%86%0A%09%09%E6%94%B9%E5%A4%A9%E5%86%99env%E7%9A%84%E6%97%B6%E5%80%99%E8%AE%B0%E5%BE%97%E5%86%99%E4%B8%AAdailybuild%E7%9A%84env%0A%09%09*/%0A
 %09%09// ser

add comments