@ohos-ports/core 1.0.113-beta.0 → 1.16.33-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +3 -0
- package/lib/api/node.js +176 -0
- package/lib/api/team.js +1889 -0
- package/lib/blocklet/downloader/blocklet-downloader.js +246 -0
- package/lib/blocklet/downloader/bundle-downloader.js +316 -0
- package/lib/blocklet/downloader/constants.js +3 -0
- package/lib/blocklet/downloader/resolve-download.js +187 -0
- package/lib/blocklet/extras.js +177 -0
- package/lib/blocklet/hooks.js +89 -0
- package/lib/blocklet/manager/base.js +49 -0
- package/lib/blocklet/manager/config-synchronizer.js +128 -0
- package/lib/blocklet/manager/disk.js +5170 -0
- package/lib/blocklet/manager/engine.js +124 -0
- package/lib/blocklet/manager/helper/install-application-from-backup.js +285 -0
- package/lib/blocklet/manager/helper/install-application-from-dev.js +72 -0
- package/lib/blocklet/manager/helper/install-application-from-general.js +209 -0
- package/lib/blocklet/manager/helper/install-component-from-dev.js +128 -0
- package/lib/blocklet/manager/helper/install-component-from-upload.js +197 -0
- package/lib/blocklet/manager/helper/install-component-from-url.js +214 -0
- package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +557 -0
- package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
- package/lib/blocklet/manager/helper/upgrade-components.js +179 -0
- package/lib/blocklet/manager/pm2-events.js +50 -0
- package/lib/blocklet/migration-dist/migration.cjs +38605 -0
- package/lib/blocklet/migration-dist/run-script.cjs +29 -0
- package/lib/blocklet/migration.js +145 -0
- package/lib/blocklet/project/connect-by-studio.js +91 -0
- package/lib/blocklet/project/connect-to-store.js +64 -0
- package/lib/blocklet/project/create-pack-release.js +293 -0
- package/lib/blocklet/project/disconnect-from-store.js +13 -0
- package/lib/blocklet/project/get-is-multiple-tenant.js +8 -0
- package/lib/blocklet/project/index.js +545 -0
- package/lib/blocklet/project/logo.png +0 -0
- package/lib/blocklet/project/publish-to-store.js +108 -0
- package/lib/blocklet/project/util.js +194 -0
- package/lib/blocklet/security/access-policy.js +131 -0
- package/lib/blocklet/security/index.js +309 -0
- package/lib/blocklet/security/response-header-policy.js +178 -0
- package/lib/blocklet/security/security-rule.js +127 -0
- package/lib/blocklet/security/utils.js +35 -0
- package/lib/blocklet/security/validator.js +40 -0
- package/lib/blocklet/storage/backup/base.js +149 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +110 -0
- package/lib/blocklet/storage/backup/blocklet.js +159 -0
- package/lib/blocklet/storage/backup/blocklets.js +109 -0
- package/lib/blocklet/storage/backup/data.js +35 -0
- package/lib/blocklet/storage/backup/disk.js +131 -0
- package/lib/blocklet/storage/backup/logs.js +24 -0
- package/lib/blocklet/storage/backup/routing-rule.js +47 -0
- package/lib/blocklet/storage/backup/spaces.js +345 -0
- package/lib/blocklet/storage/restore/base.js +74 -0
- package/lib/blocklet/storage/restore/blocklet-extras.js +89 -0
- package/lib/blocklet/storage/restore/blocklet.js +56 -0
- package/lib/blocklet/storage/restore/blocklets.js +43 -0
- package/lib/blocklet/storage/restore/disk.js +104 -0
- package/lib/blocklet/storage/restore/logs.js +21 -0
- package/lib/blocklet/storage/restore/spaces.js +174 -0
- package/lib/blocklet/storage/utils/disk.js +178 -0
- package/lib/blocklet/storage/utils/hash.js +53 -0
- package/lib/blocklet/storage/utils/zip.js +43 -0
- package/lib/cert.js +221 -0
- package/lib/crons/check-new-version.js +68 -0
- package/lib/crons/monitor-disk-usage.js +46 -0
- package/lib/crons/rotate-pm2-logs/index.js +41 -0
- package/lib/crons/rotate-pm2-logs/script.js +56 -0
- package/lib/event/auto-backup-handler.js +48 -0
- package/lib/event/index.js +520 -0
- package/lib/index.js +768 -364
- package/lib/locales/ar.js +18 -0
- package/lib/locales/de.js +21 -0
- package/lib/locales/en.js +19 -0
- package/lib/locales/es.js +21 -0
- package/lib/locales/fr.js +21 -0
- package/lib/locales/hi.js +18 -0
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +20 -0
- package/lib/locales/index.js +54 -0
- package/lib/locales/ja.js +19 -0
- package/lib/locales/ko.js +18 -0
- package/lib/locales/pt.js +20 -0
- package/lib/locales/ru.js +21 -0
- package/lib/locales/th.js +18 -0
- package/lib/locales/vi.js +18 -0
- package/lib/locales/zh-tw.js +17 -0
- package/lib/locales/zh.js +17 -0
- package/lib/migrations/1.0.21-update-config.js +34 -0
- package/lib/migrations/1.0.22-max-memory.js +40 -0
- package/lib/migrations/1.0.25.js +36 -0
- package/lib/migrations/1.0.32-update-config.js +30 -0
- package/lib/migrations/1.0.33-blocklets.js +33 -0
- package/lib/migrations/1.0.36-snapshot.js +10 -0
- package/lib/migrations/1.1.10-team.js +26 -0
- package/lib/migrations/1.1.9-snapshot.js +7 -0
- package/lib/migrations/1.16.11-component-status.js +22 -0
- package/lib/migrations/1.16.33-blocklet-security-rule.js +17 -0
- package/lib/migrations/1.16.6-chain-info.js +78 -0
- package/lib/migrations/1.16.8-component-title.js +66 -0
- package/lib/migrations/1.2.11-blocklet-registry.js +10 -0
- package/lib/migrations/1.2.2-blocklet-registry.js +10 -0
- package/lib/migrations/1.3.1-disk-alert-threshold.js +10 -0
- package/lib/migrations/1.4.5-access-key.js +18 -0
- package/lib/migrations/1.5.0-site.js +34 -0
- package/lib/migrations/1.5.15-site.js +184 -0
- package/lib/migrations/1.5.20-registry.js +15 -0
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
- package/lib/migrations/1.6.4-security.js +59 -0
- package/lib/migrations/1.6.5-security.js +60 -0
- package/lib/migrations/1.6.9-update-node-info-and-certificate.js +39 -0
- package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
- package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
- package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
- package/lib/migrations/1.7.20-blocklet-component.js +41 -0
- package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
- package/lib/migrations/README.md +71 -0
- package/lib/migrations/index.js +215 -0
- package/lib/monitor/blocklet-runtime-monitor.js +204 -0
- package/lib/monitor/get-history-list.js +37 -0
- package/lib/monitor/node-monit-sender.js +99 -0
- package/lib/monitor/node-runtime-monitor.js +205 -0
- package/lib/processes/updater.js +186 -0
- package/lib/router/helper.js +1653 -0
- package/lib/router/index.js +341 -0
- package/lib/router/manager.js +806 -0
- package/lib/states/README.md +38 -0
- package/lib/states/access-key.js +124 -0
- package/lib/states/access-policy.js +29 -0
- package/lib/states/audit-log.js +734 -0
- package/lib/states/backup.js +165 -0
- package/lib/states/base.js +25 -0
- package/lib/states/blocklet-extras.js +257 -0
- package/lib/states/blocklet.js +755 -0
- package/lib/states/cache.js +23 -0
- package/lib/states/connect-account.js +8 -0
- package/lib/states/index.js +76 -0
- package/lib/states/job.js +8 -0
- package/lib/states/migration.js +34 -0
- package/lib/states/node.js +324 -0
- package/lib/states/notification.js +81 -0
- package/lib/states/passport.js +8 -0
- package/lib/states/project.js +119 -0
- package/lib/states/release.js +50 -0
- package/lib/states/response-header-policy.js +30 -0
- package/lib/states/routing-snapshot.js +146 -0
- package/lib/states/runtime-insight.js +25 -0
- package/lib/states/security-rule.js +30 -0
- package/lib/states/session.js +53 -0
- package/lib/states/site.js +102 -0
- package/lib/states/tag.js +8 -0
- package/lib/states/traffic-insight.js +25 -0
- package/lib/states/user-session.js +8 -0
- package/lib/states/user.js +717 -0
- package/lib/states/verify-code.js +152 -0
- package/lib/states/webhook.js +66 -0
- package/lib/team/manager.js +508 -0
- package/lib/util/blocklet.js +2182 -0
- package/lib/util/cache.js +63 -0
- package/lib/util/chain.js +29 -0
- package/lib/util/default-node-config.js +46 -0
- package/lib/util/docker/blocklet-custom-dockerfile.js +92 -0
- package/lib/util/docker/check-docker-has-image.js +23 -0
- package/lib/util/docker/check-docker-installed.js +32 -0
- package/lib/util/docker/check-docker-run-history.js +18 -0
- package/lib/util/docker/check-need-run-docker.js +32 -0
- package/lib/util/docker/create-docker-image.js +65 -0
- package/lib/util/docker/debian-dockerfile.js +50 -0
- package/lib/util/docker/docker-container-prune.js +75 -0
- package/lib/util/docker/docker-exec-chown.js +39 -0
- package/lib/util/docker/docker-exec.js +68 -0
- package/lib/util/docker/docker-remove-by-name.js +20 -0
- package/lib/util/docker/get-docker-runtime-info.js +39 -0
- package/lib/util/docker/parse-docker-name.js +10 -0
- package/lib/util/docker/parse-docker-options-from-pm2.js +295 -0
- package/lib/util/docker/shard-network.js +10 -0
- package/lib/util/domain-status.js +118 -0
- package/lib/util/get-accessible-external-node-ip.js +92 -0
- package/lib/util/get-dynamic-components.js +47 -0
- package/lib/util/get-meta-from-url.js +30 -0
- package/lib/util/get-migration-scripts.js +36 -0
- package/lib/util/get-safe-env.js +12 -0
- package/lib/util/index.js +522 -0
- package/lib/util/install-external-dependencies.js +67 -0
- package/lib/util/ip.js +53 -0
- package/lib/util/launcher.js +475 -0
- package/lib/util/log.js +431 -0
- package/lib/util/maintain.js +178 -0
- package/lib/util/promise-debounce.js +29 -0
- package/lib/util/promise-once.js +14 -0
- package/lib/util/promise-spawn.js +93 -0
- package/lib/util/queue.js +44 -0
- package/lib/util/ready.js +89 -0
- package/lib/util/request.js +10 -0
- package/lib/util/requirement.js +61 -0
- package/lib/util/reset-node.js +166 -0
- package/lib/util/rotator.js +194 -0
- package/lib/util/router.js +122 -0
- package/lib/util/rpc.js +78 -0
- package/lib/util/spaces.js +102 -0
- package/lib/util/store.js +184 -0
- package/lib/util/sysinfo.js +46 -0
- package/lib/util/ua.js +54 -0
- package/lib/validators/backup.js +34 -0
- package/lib/validators/blocklet-extra.js +18 -0
- package/lib/validators/node.js +73 -0
- package/lib/validators/permission.js +38 -0
- package/lib/validators/project.js +39 -0
- package/lib/validators/role.js +64 -0
- package/lib/validators/router.js +192 -0
- package/lib/validators/space-gateway.js +33 -0
- package/lib/validators/trusted-factory.js +28 -0
- package/lib/validators/trusted-passport.js +32 -0
- package/lib/validators/user.js +62 -0
- package/lib/validators/util.js +92 -0
- package/lib/validators/webhook.js +42 -0
- package/lib/webhook/index.js +216 -0
- package/lib/webhook/reduce-queue.js +12 -0
- package/lib/webhook/sender/api/index.js +67 -0
- package/lib/webhook/sender/base.js +11 -0
- package/lib/webhook/sender/index.js +44 -0
- package/lib/webhook/sender/slack/index.js +167 -0
- package/lib/webhook/sender/wallet/index.js +62 -0
- package/package.json +107 -34
- package/examples/BatchClient.js +0 -61
- package/examples/compressor/example.js +0 -7
- package/examples/jsonrpcserver/rpcmethod.js +0 -21
- package/examples/jsonrpcserver/rpcrequest.js +0 -20
- package/examples/jsonrpcserver/rpctest.js +0 -6
- package/examples/loader-pipes/test-mc.js +0 -52
- package/examples/loader-pipes/test.js +0 -51
- package/examples/mc-test.js +0 -44
- package/examples/redisdebug.js +0 -80
- package/lib/cache/CFMemcache.js +0 -57
- package/lib/cache/CacheLoader.js +0 -217
- package/lib/cache/Memcache.js +0 -406
- package/lib/class/Class.js +0 -54
- package/lib/client/MemcacheAdapter.js +0 -139
- package/lib/client/Memcached.js +0 -142
- package/lib/client/MemcachedSocket.js +0 -570
- package/lib/client/MySQLPool.js +0 -153
- package/lib/client/PGPool.js +0 -296
- package/lib/client/Redis.js +0 -787
- package/lib/client/S3.js +0 -103
- package/lib/client/S3Client.js +0 -392
- package/lib/client/pg/CursorQueryWorker.js +0 -160
- package/lib/client/rabbitmq/RbmqChannel.js +0 -61
- package/lib/client/rabbitmq/RbmqConfig.js +0 -144
- package/lib/client/rabbitmq/RbmqConnection.js +0 -259
- package/lib/client/rabbitmq/RbmqExchange.js +0 -112
- package/lib/client/rabbitmq/RbmqIncomingMessage.js +0 -53
- package/lib/client/rabbitmq/RbmqMessage.js +0 -120
- package/lib/client/rabbitmq/RbmqOutcomingMessage.js +0 -47
- package/lib/client/rabbitmq/RbmqQueue.js +0 -87
- package/lib/client/rabbitmq/index.js +0 -8
- package/lib/common/Assertions.js +0 -184
- package/lib/common/Merge.js +0 -32
- package/lib/common/Net.js +0 -56
- package/lib/common/Process.js +0 -20
- package/lib/common/Random.js +0 -53
- package/lib/common/Sort.js +0 -19
- package/lib/common/Types.js +0 -163
- package/lib/credentials/CredentialsProvider.js +0 -45
- package/lib/credentials/Manager.js +0 -101
- package/lib/crypto/Crypto.js +0 -66
- package/lib/data/BinaryData.js +0 -363
- package/lib/data/Compressor.js +0 -83
- package/lib/data/FormData.js +0 -144
- package/lib/data/Mime.js +0 -45
- package/lib/event/ErrorEvent.js +0 -71
- package/lib/event/Event.js +0 -20
- package/lib/event/EventDispatcher.js +0 -157
- package/lib/http/ConnectionPool.js +0 -82
- package/lib/http/ExpressServer.js +0 -19
- package/lib/http/Headers.js +0 -165
- package/lib/http/Loader.js +0 -584
- package/lib/http/Message.js +0 -189
- package/lib/http/Request.js +0 -848
- package/lib/http/RequestProcessor.js +0 -150
- package/lib/http/Response.js +0 -850
- package/lib/http/Server.js +0 -267
- package/lib/http/Socket.js +0 -157
- package/lib/http/Url.js +0 -2
- package/lib/jsonrpc/JsonRpcAbstract.js +0 -109
- package/lib/jsonrpc/JsonRpcBatchRequest.js +0 -54
- package/lib/jsonrpc/JsonRpcBatchResponse.js +0 -73
- package/lib/jsonrpc/JsonRpcError.js +0 -191
- package/lib/jsonrpc/JsonRpcMethod.js +0 -67
- package/lib/jsonrpc/JsonRpcRequest.js +0 -224
- package/lib/jsonrpc/JsonRpcRequestProcessor.js +0 -366
- package/lib/jsonrpc/JsonRpcResponse.js +0 -175
- package/lib/jsonrpc/JsonRpcServer.js +0 -81
- package/lib/logger/EmptyLogger.js +0 -15
- package/lib/logger/LoggerFactory.js +0 -20
- package/lib/logger/WildFireLogger.js +0 -267
- package/lib/pattern/Pool.js +0 -187
- package/lib/pattern/decorator/AbstractDecorator.js +0 -49
- package/lib/pattern/decorator/DecoratorChain.js +0 -285
- package/lib/util/DeviceDetector.js +0 -153
- package/lib/yaml/YAML.js +0 -46
- package/patterns.conf +0 -6
- package/tests/cache/CacheLoaderSpec.js +0 -7
- package/tests/class/ClassSpec.js +0 -106
- package/tests/client/MemcachedSocketSpec.js +0 -1228
- package/tests/client/MemcachedSpec.js +0 -77
- package/tests/client/MySQLPoolSpec.js +0 -231
- package/tests/client/PGPoolSpec.js +0 -479
- package/tests/client/RedisSpec.js +0 -471
- package/tests/client/S3ClientSpec.js +0 -26
- package/tests/client/S3Spec.js +0 -129
- package/tests/client/rabbitmq/RbmqConnectionSpec.js +0 -71
- package/tests/common/AssertionsSpec.js +0 -278
- package/tests/common/NetSpec.js +0 -6
- package/tests/common/RandomSpec.js +0 -35
- package/tests/common/TypesSpec.js +0 -7
- package/tests/credentials/CredentialsProviderSpec.js +0 -46
- package/tests/crypto/CryptoSpec.js +0 -33
- package/tests/data/BinaryDataSpec.js +0 -50
- package/tests/data/CompressorSpec.js +0 -7
- package/tests/data/FormDataSpec.js +0 -7
- package/tests/data/MimeSpec.js +0 -7
- package/tests/event/ErrorEventSpec.js +0 -20
- package/tests/event/EventDispatcherSpec.js +0 -319
- package/tests/event/EventSpec.js +0 -17
- package/tests/http/ConnectionPoolSpec.js +0 -7
- package/tests/http/HeadersSpec.js +0 -79
- package/tests/http/LoaderSpec.js +0 -43
- package/tests/http/MessageSpec.js +0 -251
- package/tests/http/RequestProcessorSpec.js +0 -124
- package/tests/http/RequestSpec.js +0 -651
- package/tests/http/ResponseSpec.js +0 -491
- package/tests/http/ServerSpec.js +0 -7
- package/tests/http/SocketSpec.js +0 -7
- package/tests/http/UrlSpec.js +0 -14
- package/tests/jsonrpc/JsonRpcAbstractSpec.js +0 -20
- package/tests/jsonrpc/JsonRpcBatchRequestSpec.js +0 -31
- package/tests/jsonrpc/JsonRpcBatchResponseSpec.js +0 -38
- package/tests/jsonrpc/JsonRpcErrorSpec.js +0 -58
- package/tests/jsonrpc/JsonRpcMethodSpec.js +0 -7
- package/tests/jsonrpc/JsonRpcRequestProcessorSpec.js +0 -271
- package/tests/jsonrpc/JsonRpcRequestSpec.js +0 -70
- package/tests/jsonrpc/JsonRpcResponseSpec.js +0 -63
- package/tests/jsonrpc/JsonRpcServerSpec.js +0 -42
- package/tests/pattern/PoolSpec.js +0 -180
- package/tests/pattern/decorator/AbstractDecoratorSpec.js +0 -7
- package/tests/pattern/decorator/DecoratorChainSpec.js +0 -7
- package/tests/yaml/YAMLSpec.js +0 -132
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
/* global it, expect, runs, jasmine, waitsFor, describe, spyOn, beforeEach, afterEach */
|
|
2
|
-
var rewire = require('rewire');
|
|
3
|
-
//var redis = require('redis');
|
|
4
|
-
var CredentialsProvider = require('../../lib/credentials/CredentialsProvider.js').CredentialsProvider;
|
|
5
|
-
var modulePath = './../../lib/client/Redis.js';
|
|
6
|
-
|
|
7
|
-
describe('Redis', function () {
|
|
8
|
-
|
|
9
|
-
describe('should be truthy', function () {
|
|
10
|
-
beforeEach(function() {
|
|
11
|
-
jasmine.Clock.useMock();
|
|
12
|
-
jasmine.Clock.tick(1000);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should require', function () {
|
|
16
|
-
var Redis = require(modulePath).Redis;
|
|
17
|
-
expect(Redis).toBeTruthy();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should not throw', function () {
|
|
21
|
-
expect(function () {
|
|
22
|
-
require(modulePath);
|
|
23
|
-
}).not.toThrow();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('redis connection timeout', function() {
|
|
29
|
-
var RedisMock = null;
|
|
30
|
-
var Redis = null;
|
|
31
|
-
var mockClient = null;
|
|
32
|
-
var redis;
|
|
33
|
-
|
|
34
|
-
beforeEach(function() {
|
|
35
|
-
jasmine.Clock.useMock();
|
|
36
|
-
console.log();
|
|
37
|
-
RedisMock = rewire(modulePath);
|
|
38
|
-
/* module */
|
|
39
|
-
Redis = RedisMock.Redis;
|
|
40
|
-
/* client */
|
|
41
|
-
redis = RedisMock.__get__('redis');
|
|
42
|
-
|
|
43
|
-
//console.log('r', redis);
|
|
44
|
-
mockClient = jasmine.createSpy();
|
|
45
|
-
|
|
46
|
-
mockClient.on = jasmine.createSpy('on');
|
|
47
|
-
mockClient.on.andCallFake(function (ev, cb) {
|
|
48
|
-
if (ev === 'ready') {
|
|
49
|
-
mockClient.ready = true;
|
|
50
|
-
cb();
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
mockClient.ping = jasmine.createSpy('ping');
|
|
55
|
-
mockClient.quit = jasmine.createSpy('quit');
|
|
56
|
-
|
|
57
|
-
spyOn(redis, 'createClient');
|
|
58
|
-
|
|
59
|
-
redis.createClient.andCallFake(function(host, port, options) {
|
|
60
|
-
mockClient.options = options;
|
|
61
|
-
return mockClient;
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
afterEach(function() {
|
|
66
|
-
jasmine.Clock.reset();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it ('should run ping command every defined timeout', function() {
|
|
70
|
-
var options = {
|
|
71
|
-
'connections': 2,
|
|
72
|
-
'hosts': [{
|
|
73
|
-
'host': 'localhost',
|
|
74
|
-
'port': 1234
|
|
75
|
-
}],
|
|
76
|
-
'hbInterval': 1000,
|
|
77
|
-
'hbTimeout': 1000
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
var r1 = new Redis(new CredentialsProvider(options));
|
|
81
|
-
jasmine.Clock.tick(options.hbInterval + 100);
|
|
82
|
-
|
|
83
|
-
expect(mockClient.ping).toHaveBeenCalled();
|
|
84
|
-
r1.destroy();
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it ('should run disconnect client on ping command error', function() {
|
|
88
|
-
var options = {
|
|
89
|
-
'connections': 2,
|
|
90
|
-
'hosts': [{
|
|
91
|
-
'host': 'localhost',
|
|
92
|
-
'port': 1234
|
|
93
|
-
}],
|
|
94
|
-
'hbInterval': 1000,
|
|
95
|
-
'hbTimeout': 1000
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
var r2 = new Redis(new CredentialsProvider(options));
|
|
99
|
-
|
|
100
|
-
jasmine.Clock.tick(options.hbInterval);
|
|
101
|
-
expect(mockClient.ping).toHaveBeenCalled();
|
|
102
|
-
|
|
103
|
-
jasmine.Clock.tick(options.hbTimeout);
|
|
104
|
-
expect(mockClient.quit).toHaveBeenCalledWith(jasmine.any(Function));
|
|
105
|
-
|
|
106
|
-
r2.destroy();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('methods', function () {
|
|
111
|
-
var RedisMock = null;
|
|
112
|
-
var Redis = null;
|
|
113
|
-
var mockClient = null;
|
|
114
|
-
var redis;
|
|
115
|
-
|
|
116
|
-
beforeEach(function () {
|
|
117
|
-
jasmine.Clock.useMock();
|
|
118
|
-
|
|
119
|
-
RedisMock = rewire(modulePath);
|
|
120
|
-
/* module */
|
|
121
|
-
Redis = RedisMock.Redis;
|
|
122
|
-
/* client */
|
|
123
|
-
redis = RedisMock.__get__('redis');
|
|
124
|
-
Redis.prototype._heartbeat = jasmine.createSpy('_hb')
|
|
125
|
-
|
|
126
|
-
//console.log('r', redis);
|
|
127
|
-
mockClient = jasmine.createSpy();
|
|
128
|
-
mockClient.on = jasmine.createSpy();
|
|
129
|
-
mockClient.on.andCallFake(function (ev, cb) {
|
|
130
|
-
if (ev === 'ready') {
|
|
131
|
-
cb();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
spyOn(redis, 'createClient');
|
|
135
|
-
redis.createClient.andReturn(mockClient);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('multiton', function () {
|
|
139
|
-
var cp = new CredentialsProvider({
|
|
140
|
-
'hosts': []
|
|
141
|
-
});
|
|
142
|
-
var r1 = new Redis(cp);
|
|
143
|
-
var r2 = new Redis(cp);
|
|
144
|
-
expect(r1).toEqual(r2);
|
|
145
|
-
r1.destroy();
|
|
146
|
-
r2.destroy();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('num connections', function () {
|
|
150
|
-
var cp = new CredentialsProvider({
|
|
151
|
-
'connections': 2,
|
|
152
|
-
'hosts': [{
|
|
153
|
-
'host': 'localhost',
|
|
154
|
-
'port': 1234
|
|
155
|
-
}]
|
|
156
|
-
});
|
|
157
|
-
var r1 = new Redis(cp);
|
|
158
|
-
expect(redis.createClient).toHaveBeenCalled();
|
|
159
|
-
expect(mockClient.on).toHaveBeenCalled();
|
|
160
|
-
r1.destroy();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('set', function () {
|
|
164
|
-
var called = null,
|
|
165
|
-
called2 = null,
|
|
166
|
-
r1, testKey = 'a',
|
|
167
|
-
testVal = 'b',
|
|
168
|
-
mockCb;
|
|
169
|
-
runs(function () {
|
|
170
|
-
mockClient.set = jasmine.createSpy();
|
|
171
|
-
mockClient.set.andCallFake(function (key, val, cb) {
|
|
172
|
-
called = true;
|
|
173
|
-
cb(null, null);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
var cp = new CredentialsProvider({
|
|
177
|
-
'connections': 2,
|
|
178
|
-
'hosts': [{
|
|
179
|
-
'host': 'localhost',
|
|
180
|
-
'port': 1234
|
|
181
|
-
}]
|
|
182
|
-
});
|
|
183
|
-
r1 = new Redis(cp);
|
|
184
|
-
mockCb = jasmine.createSpy();
|
|
185
|
-
mockCb.andCallFake(function () {
|
|
186
|
-
called2 = true;
|
|
187
|
-
});
|
|
188
|
-
r1.set(testKey, testVal, mockCb);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
waitsFor(function () {
|
|
192
|
-
return (called != null && called2 != null);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
runs(function () {
|
|
196
|
-
expect(called).toBeTruthy();
|
|
197
|
-
expect(called2).toBeTruthy();
|
|
198
|
-
expect(mockClient.set).toHaveBeenCalled();
|
|
199
|
-
expect(mockClient.set.mostRecentCall.args[0]).toEqual(testKey);
|
|
200
|
-
expect(mockClient.set.mostRecentCall.args[1]).toEqual(testVal);
|
|
201
|
-
expect(mockCb).toHaveBeenCalledWith(null, null);
|
|
202
|
-
r1.destroy();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
it('get', function () {
|
|
208
|
-
var called = null,
|
|
209
|
-
called2 = null,
|
|
210
|
-
r1, testKey = 'a',
|
|
211
|
-
testVal = 'b',
|
|
212
|
-
mockCb;
|
|
213
|
-
runs(function () {
|
|
214
|
-
mockClient.get = jasmine.createSpy();
|
|
215
|
-
mockClient.get.andCallFake(function (key, cb) {
|
|
216
|
-
called = true;
|
|
217
|
-
cb(null, testVal);
|
|
218
|
-
});
|
|
219
|
-
var cp = new CredentialsProvider({
|
|
220
|
-
'connections': 2,
|
|
221
|
-
'hosts': [{
|
|
222
|
-
'host': 'localhost',
|
|
223
|
-
'port': 1234
|
|
224
|
-
}]
|
|
225
|
-
});
|
|
226
|
-
r1 = new Redis(cp);
|
|
227
|
-
mockCb = jasmine.createSpy();
|
|
228
|
-
mockCb.andCallFake(function () {
|
|
229
|
-
called2 = true;
|
|
230
|
-
});
|
|
231
|
-
r1.get(testKey, mockCb);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
waitsFor(function () {
|
|
235
|
-
return (called != null && called2 != null);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
runs(function () {
|
|
239
|
-
expect(called).toBeTruthy();
|
|
240
|
-
expect(called2).toBeTruthy();
|
|
241
|
-
expect(mockClient.get).toHaveBeenCalled();
|
|
242
|
-
expect(mockClient.get.mostRecentCall.args[0]).toEqual(testKey);
|
|
243
|
-
expect(mockCb).toHaveBeenCalledWith(null, testVal);
|
|
244
|
-
r1.destroy();
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('set', function () {
|
|
249
|
-
var called = null,
|
|
250
|
-
called2 = null,
|
|
251
|
-
mockCb, cp, r1, testKey = 'a',
|
|
252
|
-
testVal = 'b';
|
|
253
|
-
runs(function () {
|
|
254
|
-
mockClient.set = jasmine.createSpy();
|
|
255
|
-
mockClient.set.andCallFake(function (key, value, cb) {
|
|
256
|
-
called = true;
|
|
257
|
-
cb(null, null);
|
|
258
|
-
});
|
|
259
|
-
cp = new CredentialsProvider({
|
|
260
|
-
'connections': 2,
|
|
261
|
-
'hosts': [{
|
|
262
|
-
'host': 'localhost',
|
|
263
|
-
'port': 1234
|
|
264
|
-
}]
|
|
265
|
-
});
|
|
266
|
-
r1 = new Redis(cp);
|
|
267
|
-
mockCb = jasmine.createSpy();
|
|
268
|
-
mockCb.andCallFake(function () {
|
|
269
|
-
called2 = true;
|
|
270
|
-
});
|
|
271
|
-
r1.set(testKey, testVal, mockCb);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
waitsFor(function () {
|
|
275
|
-
return (called != null && called2 != null);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
runs(function () {
|
|
279
|
-
expect(called).toBeTruthy();
|
|
280
|
-
expect(called2).toBeTruthy();
|
|
281
|
-
expect(mockClient.set).toHaveBeenCalled();
|
|
282
|
-
expect(mockClient.set.mostRecentCall.args[0]).toEqual(testKey);
|
|
283
|
-
expect(mockClient.set.mostRecentCall.args[1]).toEqual(testVal);
|
|
284
|
-
expect(mockCb).toHaveBeenCalledWith(null, null);
|
|
285
|
-
r1.destroy();
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('hmget', function () {
|
|
290
|
-
var called = null,
|
|
291
|
-
called2 = null,
|
|
292
|
-
mockCb, cp, r1, testKey = 'a',
|
|
293
|
-
testField = 'b',
|
|
294
|
-
testVal = 'c';
|
|
295
|
-
runs(function () {
|
|
296
|
-
mockClient.hmget = jasmine.createSpy();
|
|
297
|
-
mockClient.hmget.andCallFake(function (key, field, cb) {
|
|
298
|
-
called = true;
|
|
299
|
-
cb(null, testVal);
|
|
300
|
-
});
|
|
301
|
-
cp = new CredentialsProvider({
|
|
302
|
-
'connections': 2,
|
|
303
|
-
'hosts': [{
|
|
304
|
-
'host': 'localhost',
|
|
305
|
-
'port': 1234
|
|
306
|
-
}]
|
|
307
|
-
});
|
|
308
|
-
r1 = new Redis(cp);
|
|
309
|
-
mockCb = jasmine.createSpy();
|
|
310
|
-
mockCb.andCallFake(function () {
|
|
311
|
-
called2 = true;
|
|
312
|
-
});
|
|
313
|
-
r1.hmget(testKey, testField, mockCb);
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
waitsFor(function () {
|
|
317
|
-
return (called != null && called2 != null);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
runs(function () {
|
|
321
|
-
expect(called).toBeTruthy();
|
|
322
|
-
expect(called2).toBeTruthy();
|
|
323
|
-
expect(mockClient.hmget).toHaveBeenCalled();
|
|
324
|
-
expect(mockClient.hmget.mostRecentCall.args[0]).toEqual(testKey);
|
|
325
|
-
expect(mockClient.hmget.mostRecentCall.args[1]).toEqual(testField);
|
|
326
|
-
expect(mockCb).toHaveBeenCalledWith(null, testVal);
|
|
327
|
-
r1.destroy();
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it('hgetall', function () {
|
|
332
|
-
var called = null,
|
|
333
|
-
called2 = null,
|
|
334
|
-
mockCb, cp, r1, testKey = 'a',
|
|
335
|
-
testVal = 'c';
|
|
336
|
-
runs(function () {
|
|
337
|
-
mockClient.hgetall = jasmine.createSpy();
|
|
338
|
-
mockClient.hgetall.andCallFake(function (key, cb) {
|
|
339
|
-
called = true;
|
|
340
|
-
cb(null, testVal);
|
|
341
|
-
});
|
|
342
|
-
cp = new CredentialsProvider({
|
|
343
|
-
'connections': 2,
|
|
344
|
-
'hosts': [{
|
|
345
|
-
'host': 'localhost',
|
|
346
|
-
'port': 1234
|
|
347
|
-
}]
|
|
348
|
-
});
|
|
349
|
-
r1 = new Redis(cp);
|
|
350
|
-
mockCb = jasmine.createSpy();
|
|
351
|
-
mockCb.andCallFake(function () {
|
|
352
|
-
called2 = true;
|
|
353
|
-
});
|
|
354
|
-
r1.hgetall(testKey, mockCb);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
waitsFor(function () {
|
|
358
|
-
return (called != null && called2 != null);
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
runs(function () {
|
|
362
|
-
expect(called).toBeTruthy();
|
|
363
|
-
expect(called2).toBeTruthy();
|
|
364
|
-
expect(mockClient.hgetall).toHaveBeenCalled();
|
|
365
|
-
expect(mockClient.hgetall.mostRecentCall.args[0]).toEqual(testKey);
|
|
366
|
-
expect(mockCb).toHaveBeenCalledWith(null, testVal);
|
|
367
|
-
r1.destroy();
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it('del', function () {
|
|
372
|
-
var called = null,
|
|
373
|
-
called2 = null,
|
|
374
|
-
testKey = 'a',
|
|
375
|
-
cp, r1, mockCb;
|
|
376
|
-
|
|
377
|
-
runs(function () {
|
|
378
|
-
mockClient.del = jasmine.createSpy();
|
|
379
|
-
mockClient.del.andCallFake(function (key, cb) {
|
|
380
|
-
called = true;
|
|
381
|
-
cb(null, null);
|
|
382
|
-
});
|
|
383
|
-
cp = new CredentialsProvider({
|
|
384
|
-
'connections': 2,
|
|
385
|
-
'hosts': [{
|
|
386
|
-
'host': 'localhost',
|
|
387
|
-
'port': 1234
|
|
388
|
-
}]
|
|
389
|
-
});
|
|
390
|
-
r1 = new Redis(cp);
|
|
391
|
-
mockCb = jasmine.createSpy();
|
|
392
|
-
mockCb.andCallFake(function () {
|
|
393
|
-
called2 = true;
|
|
394
|
-
});
|
|
395
|
-
r1.del(testKey, mockCb);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
waitsFor(function () {
|
|
399
|
-
return (called != null && called2 != null);
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
runs(function () {
|
|
404
|
-
expect(called).toBeTruthy();
|
|
405
|
-
expect(called2).toBeTruthy();
|
|
406
|
-
expect(mockClient.del).toHaveBeenCalled();
|
|
407
|
-
expect(mockClient.del.mostRecentCall.args[0]).toEqual(testKey);
|
|
408
|
-
expect(mockCb).toHaveBeenCalledWith(null, null);
|
|
409
|
-
r1.destroy();
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
describe('when command error', function () {
|
|
414
|
-
beforeEach(function () {
|
|
415
|
-
var cp = new CredentialsProvider({
|
|
416
|
-
'connections': 2,
|
|
417
|
-
'hosts': [{
|
|
418
|
-
'host': 'localhost',
|
|
419
|
-
'port': 1234
|
|
420
|
-
}]
|
|
421
|
-
});
|
|
422
|
-
this.redis = new Redis(cp);
|
|
423
|
-
this.callback = jasmine.createSpy('set_callback');
|
|
424
|
-
mockClient.set = jasmine.createSpy();
|
|
425
|
-
mockClient.set.andCallFake(function (key, data, callback) {
|
|
426
|
-
callback('error', null);
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
afterEach(function () {
|
|
431
|
-
this.redis.destroy();
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
describe('callback', function () {
|
|
435
|
-
beforeEach(function () {
|
|
436
|
-
this.redis.set('key', 'data', this.callback);
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it('should be called', function () {
|
|
440
|
-
expect(this.callback).toHaveBeenCalled();
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
it('should be called with error', function () {
|
|
444
|
-
expect(this.callback).toHaveBeenCalledWith('error', null);
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
describe('console.warn', function () {
|
|
449
|
-
beforeEach(function () {
|
|
450
|
-
this.consoleWarnSpy = jasmine.createSpy('consoleWarnSpy');
|
|
451
|
-
var consoleMock = Object.create(RedisMock.__get__('console'));
|
|
452
|
-
consoleMock.warn = this.consoleWarnSpy;
|
|
453
|
-
RedisMock.__set__({
|
|
454
|
-
console: consoleMock
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
this.redis.set('key', 'data', this.callback);
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
it('should be called', function () {
|
|
461
|
-
expect(this.consoleWarnSpy).toHaveBeenCalled();
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it('should be called with params', function () {
|
|
465
|
-
expect(this.consoleWarnSpy).toHaveBeenCalledWith(
|
|
466
|
-
'Redis/Error cmd=%s error="%s"', 'set', 'error');
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
});
|
|
471
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var rewire = require('rewire');
|
|
2
|
-
var modulePath = '../../lib/client/S3Client.js';
|
|
3
|
-
|
|
4
|
-
describe('S3Client', function () {
|
|
5
|
-
describe('require', function () {
|
|
6
|
-
it('should be truthy', function () {
|
|
7
|
-
var S3Client = require(modulePath).S3Client;
|
|
8
|
-
expect(S3Client).toBeTruthy();
|
|
9
|
-
});
|
|
10
|
-
it('should not throw exception ', function () {
|
|
11
|
-
expect(function () {
|
|
12
|
-
var S3Client = require(modulePath).S3Client;
|
|
13
|
-
}).not.toThrow();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('methods', function () {
|
|
18
|
-
var S3ClientMock;
|
|
19
|
-
var S3Client;
|
|
20
|
-
|
|
21
|
-
beforeEach(function () {
|
|
22
|
-
S3ClientMock = rewire(modulePath);
|
|
23
|
-
S3Client = S3ClientMock.S3Client;
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
package/tests/client/S3Spec.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
describe('S3', function () {
|
|
2
|
-
var S3 = null;
|
|
3
|
-
it('require', function () {
|
|
4
|
-
expect(function () {
|
|
5
|
-
S3 = require('../../lib/client/S3.js').S3;
|
|
6
|
-
}).not.toThrow();
|
|
7
|
-
expect(S3).toBeTruthy();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('create client', function () {
|
|
11
|
-
var knox = require('knox'), created = 0, s3;
|
|
12
|
-
|
|
13
|
-
runs(function () {
|
|
14
|
-
spyOn(knox, 'createClient');
|
|
15
|
-
knox.createClient.andCallFake(function () {
|
|
16
|
-
created++;
|
|
17
|
-
})
|
|
18
|
-
s3 = new S3();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
waitsFor(function () {
|
|
22
|
-
return created > 0;
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
runs(function () {
|
|
26
|
-
expect(created).toEqual(1);
|
|
27
|
-
})
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('get file', function () {
|
|
31
|
-
var knox = require('knox'), events = require('events'),
|
|
32
|
-
created = 0, s3, err, res, body = 'aaaa';
|
|
33
|
-
|
|
34
|
-
runs(function () {
|
|
35
|
-
spyOn(knox, 'createClient');
|
|
36
|
-
knox.createClient.andCallFake(function () {
|
|
37
|
-
var Client = function () {
|
|
38
|
-
this.statusCode = 200;
|
|
39
|
-
this.headers = {};
|
|
40
|
-
};
|
|
41
|
-
Client.prototype = Object.create(events.EventEmitter.prototype);
|
|
42
|
-
Client.prototype.get = function (filename, headers) {
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
Client.prototype.end = function () {
|
|
46
|
-
process.nextTick((function () {
|
|
47
|
-
this.emit('response', this);
|
|
48
|
-
process.nextTick((function() {
|
|
49
|
-
this.emit('data', new Buffer(body));
|
|
50
|
-
process.nextTick((function () {
|
|
51
|
-
this.emit('end');
|
|
52
|
-
}).bind(this));
|
|
53
|
-
}).bind(this), 0);
|
|
54
|
-
}).bind(this));
|
|
55
|
-
}
|
|
56
|
-
created++;
|
|
57
|
-
return new Client();
|
|
58
|
-
});
|
|
59
|
-
s3 = new S3();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
waitsFor(function () {
|
|
63
|
-
return created > 0;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
runs(function () {
|
|
67
|
-
s3.get('aaaa', function (e, r) {
|
|
68
|
-
err = e;
|
|
69
|
-
res = r;
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
waitsFor(function () {
|
|
74
|
-
return res != undefined;
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
runs(function () {
|
|
78
|
-
var res_body = res.getBody();
|
|
79
|
-
expect(err).toBeFalsy();
|
|
80
|
-
expect(new Buffer(res_body.toString(), 'base64').toString()).toEqual(body);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('put file', function () {
|
|
85
|
-
var knox = require('knox'), events = require('events'),
|
|
86
|
-
created = 0, s3, err, body = 'aaaa';
|
|
87
|
-
|
|
88
|
-
runs(function () {
|
|
89
|
-
spyOn(knox, 'createClient');
|
|
90
|
-
knox.createClient.andCallFake(function () {
|
|
91
|
-
var Client = function () {
|
|
92
|
-
this.statusCode = 200;
|
|
93
|
-
this.headers = {};
|
|
94
|
-
};
|
|
95
|
-
Client.prototype = Object.create(events.EventEmitter.prototype);
|
|
96
|
-
Client.prototype.put = function (filename, headers) {
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
Client.prototype.end = function () {
|
|
100
|
-
process.nextTick((function () {
|
|
101
|
-
this.emit('response', this);
|
|
102
|
-
}).bind(this));
|
|
103
|
-
}
|
|
104
|
-
created++;
|
|
105
|
-
return new Client();
|
|
106
|
-
});
|
|
107
|
-
s3 = new S3();
|
|
108
|
-
s3.addEventListener(S3.Event.LOADED, function () {
|
|
109
|
-
err = false;
|
|
110
|
-
}, this);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
waitsFor(function () {
|
|
114
|
-
return created > 0;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
runs(function () {
|
|
118
|
-
s3.set('aaaa');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
waitsFor(function () {
|
|
122
|
-
return err != undefined;
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
runs(function () {
|
|
126
|
-
expect(err).toBeFalsy();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
})
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
var rewire = require('rewire');
|
|
2
|
-
var modulePath = '../../../lib/client/rabbitmq/RbmqConnection.js';
|
|
3
|
-
//set debug mode (workaround for rewire)
|
|
4
|
-
process.env['NODE_DEBUG_AMQP'] = true;
|
|
5
|
-
|
|
6
|
-
// var RbmqConnection = require('../../../lib/client/rabbitmq/RbmqConnection.js').RbmqConnection;
|
|
7
|
-
describe('RbmqConnection', function () {
|
|
8
|
-
var RbmqConnection = null;
|
|
9
|
-
var RbmqConnectionMock = null;
|
|
10
|
-
|
|
11
|
-
it('require', function () {
|
|
12
|
-
RbmqConnection = require(modulePath).RbmqConnection;
|
|
13
|
-
|
|
14
|
-
expect(RbmqConnection).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
beforeEach(function () {
|
|
18
|
-
RbmqConnectionMock = rewire(modulePath);
|
|
19
|
-
RbmqConnection = RbmqConnectionMock.RbmqConnection;
|
|
20
|
-
|
|
21
|
-
this._mockClient = {
|
|
22
|
-
eventsMock : {},
|
|
23
|
-
createConnection : function() {
|
|
24
|
-
console.log('create connection');
|
|
25
|
-
if (typeof this.eventsMock.connect === 'function') {
|
|
26
|
-
this.eventsMock.connect();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return this;
|
|
30
|
-
},
|
|
31
|
-
on : function(event, cb) {
|
|
32
|
-
this.eventsMock[event] = cb;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
RbmqConnectionMock.__set__('amqp', this._mockClient);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('connect with weight', function () {
|
|
40
|
-
|
|
41
|
-
var hosts = [{
|
|
42
|
-
host: '127.0.0.1',
|
|
43
|
-
port: 12345,
|
|
44
|
-
weight: 1
|
|
45
|
-
}, {
|
|
46
|
-
host: '127.0.0.2',
|
|
47
|
-
port: 12345,
|
|
48
|
-
weight: 2
|
|
49
|
-
}, {
|
|
50
|
-
host: '127.0.0.3',
|
|
51
|
-
port: 12345,
|
|
52
|
-
weight: 3
|
|
53
|
-
}];
|
|
54
|
-
|
|
55
|
-
var createConnection = jasmine.createSpy();
|
|
56
|
-
createConnection.andCallFake(function (config) {
|
|
57
|
-
expect(config).toEqual(hosts[2]);
|
|
58
|
-
return this;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
RbmqConnectionMock.__set__('createConnection', createConnection);
|
|
62
|
-
|
|
63
|
-
var connection = new RbmqConnection({
|
|
64
|
-
enableHostWeight: true,
|
|
65
|
-
hosts: hosts
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
connection.connect();
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
});
|