Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 21, 2025
1 parent 1b6294a commit e1bab70
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 3 deletions.
12 changes: 12 additions & 0 deletions __snapshots__/redis.test.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exports['test/redis.test.js default config should make default config stable 1'] = {
"default": {},
"app": true,
"agent": false,
"supportTimeCommand": true,
"client": {
"host": "127.0.0.1",
"port": 6379,
"password": "",
"db": "0"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint": "8",
"eslint-config-egg": "14",
"rimraf": "6",
"snap-shot-it": "^7.9.10",
"tshy": "3",
"tshy-after": "1",
"typescript": "5"
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/apps/redisapp-default/app/controller/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = app => {
return class HomeController extends app.Controller {
async index() {
const { ctx, app } = this;
await app.redis.set('foo', 'bar');
ctx.body = await app.redis.get('foo');
}
};
};
5 changes: 5 additions & 0 deletions test/fixtures/apps/redisapp-default/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function(app) {
app.get('/', 'home.index');
};
16 changes: 16 additions & 0 deletions test/fixtures/apps/redisapp-default/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.redis = {
client: {
host: '127.0.0.1',
port: 6379,
password: '',
db: '0',
},
};

exports.logger = {
coreLogger: {
level: 'INFO',
},
};

exports.keys = 'keys';
3 changes: 3 additions & 0 deletions test/fixtures/apps/redisapp-default/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "redisapp"
}
4 changes: 1 addition & 3 deletions test/fixtures/apps/redisapp/config/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';

exports.redis = {
client: {
host: '127.0.0.1',
port: 6379,
password: '',
db: '0',
},
agent:true,
agent: true,
};

exports.logger = {
Expand Down
24 changes: 24 additions & 0 deletions test/redis.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
import compile from 'node:child_process';
import path from 'node:path';
import { mm, MockApplication } from '@eggjs/mock';
import snapshot from 'snap-shot-it';

describe('test/redis.test.js', () => {
describe('default config', () => {
let app: MockApplication;
before(async () => {
app = mm.app({
baseDir: 'apps/redisapp-default',
});
await app.ready();
});
after(() => app.close());
afterEach(mm.restore);

it('should make default config stable', () => {
snapshot(app.config.redis);
});

it('should query', () => {
return app.httpRequest()
.get('/')
.expect(200)
.expect('bar');
});
});

describe('single client', () => {
let app: MockApplication;
before(async () => {
Expand Down

0 comments on commit e1bab70

Please sign in to comment.