提交 f7df2c45 编写于 作者: Q Quinton.Xu

add test

上级 96b082ab
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
## Install ## Install
```bash ```bash
$ npm i node-apollo --save-dev --registry=http://http://116.62.161.40:7002 $ npm i node-apollo --save-dev
``` ```
## Usage ## Usage
......
'use strict'; 'use strict';
const urllib = require('urllib'); const urllib = require('urllib');
const assert = require('assert');
const helper = require('./helper'); const helper = require('./helper');
module.exports = { module.exports = {
remoteConfigService: async (token, config) => { remoteConfigService: async (config) => {
assert(config, 'param config is required');
assert(config.token, 'param token is required');
const options = { const options = {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json;charset=UTF-8', 'Content-Type': 'application/json;charset=UTF-8',
authorization: token, authorization: config.token,
}, },
rejectUnauthorized: false, rejectUnauthorized: false,
contentType: 'json', contentType: 'json',
dataType: 'json', dataType: 'json',
}; };
const res = await urllib.request(helper.getAllConfigFromApolloUri(config), options); const res = await urllib.request(helper.getAllConfigFromApolloUri(config), options);
console.log(res.data)
return helper.mergeConfig(res.data); return helper.mergeConfig(res.data);
// ctx.app.config = 2
}, },
}; };
\ No newline at end of file
{ {
"name": "node-apollo", "name": "node-apollo",
"version": "1.0.0", "version": "1.0.3",
"description": "携程Apollo配置中心SDK。", "description": "携程Apollo配置中心SDK。",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
"mocha": "^3.5.3" "mocha": "^3.5.3"
}, },
"dependencies": { "dependencies": {
"test": "^1.0.0",
"urllib": "^2.25.0" "urllib": "^2.25.0"
} }
} }
...@@ -6,14 +6,14 @@ const apollo = require('../index.js'); ...@@ -6,14 +6,14 @@ const apollo = require('../index.js');
describe('#index', function () { describe('#index', function () {
it('index.remoteConfigService', async () => { it('index.remoteConfigService', async () => {
const config = { const config = {
configServerUrl: 'http://116.62.161.40:8070', configServerUrl: 'http://example.com',
appId: 'gnetlink-cms-api', appId: '<appId>',
clusterName: 'default', clusterName: 'default',
namespaceName: '', namespaceName: '',
apolloEnv: 'dev', apolloEnv: 'dev',
// clientIp: '', // clientIp: '',
}; };
const token = '9037a4e8c14c3d61ac5dbbdfa379fc56f0e098ff'; const token = '<apollo access token>';
const result = await apollo.remoteConfigService(token, config); const result = await apollo.remoteConfigService(token, config);
assert(Object.keys(result).length > 0, 'Read config failed'); assert(Object.keys(result).length > 0, 'Read config failed');
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册