From f7df2c4521fe0be09d1dc8b5cfac449f9b1cc954 Mon Sep 17 00:00:00 2001 From: "Quinton.Xu" Date: Fri, 22 Sep 2017 14:05:31 +0800 Subject: [PATCH] add test --- README.md | 2 +- lib/apollo.js | 9 +++++---- package.json | 3 ++- test/index.js | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f87999d..63cc59b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Install ```bash -$ npm i node-apollo --save-dev --registry=http://http://116.62.161.40:7002 +$ npm i node-apollo --save-dev ``` ## Usage diff --git a/lib/apollo.js b/lib/apollo.js index cc0a977..19df687 100644 --- a/lib/apollo.js +++ b/lib/apollo.js @@ -1,23 +1,24 @@ 'use strict'; const urllib = require('urllib'); +const assert = require('assert'); const helper = require('./helper'); module.exports = { - remoteConfigService: async (token, config) => { + remoteConfigService: async (config) => { + assert(config, 'param config is required'); + assert(config.token, 'param token is required'); const options = { method: 'GET', headers: { 'Content-Type': 'application/json;charset=UTF-8', - authorization: token, + authorization: config.token, }, rejectUnauthorized: false, contentType: 'json', dataType: 'json', }; const res = await urllib.request(helper.getAllConfigFromApolloUri(config), options); - console.log(res.data) return helper.mergeConfig(res.data); - // ctx.app.config = 2 }, }; \ No newline at end of file diff --git a/package.json b/package.json index b181a02..6e28c55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-apollo", - "version": "1.0.0", + "version": "1.0.3", "description": "携程Apollo配置中心SDK。", "main": "index.js", "scripts": { @@ -21,6 +21,7 @@ "mocha": "^3.5.3" }, "dependencies": { + "test": "^1.0.0", "urllib": "^2.25.0" } } diff --git a/test/index.js b/test/index.js index 93cb45f..1604817 100644 --- a/test/index.js +++ b/test/index.js @@ -6,14 +6,14 @@ const apollo = require('../index.js'); describe('#index', function () { it('index.remoteConfigService', async () => { const config = { - configServerUrl: 'http://116.62.161.40:8070', - appId: 'gnetlink-cms-api', + configServerUrl: 'http://example.com', + appId: '', clusterName: 'default', namespaceName: '', apolloEnv: 'dev', // clientIp: '', }; - const token = '9037a4e8c14c3d61ac5dbbdfa379fc56f0e098ff'; + const token = ''; const result = await apollo.remoteConfigService(token, config); assert(Object.keys(result).length > 0, 'Read config failed'); }); -- GitLab