From 2285ae6877029a3baa319c2a6847cc0ed28336cc Mon Sep 17 00:00:00 2001 From: Alexander Pankratov Date: Wed, 5 Sep 2018 13:00:12 +0200 Subject: [PATCH 1/3] adding ability to specify firewall network --- package.json | 2 +- src/firewall.js | 2 +- test/firewall.js | 22 ++++++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 37716f94..50cd19a8 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "compute engine" ], "scripts": { - "cover": "nyc --reporter=lcov mocha test/*.js && nyc report", + "cover": "nyc --reporter=lcov mocha test/*$MATCH*.js && nyc report", "docs": "jsdoc -c .jsdoc.js", "generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json", "lint": "eslint '**/*.js'", diff --git a/src/firewall.js b/src/firewall.js index 2b12379f..362ab554 100644 --- a/src/firewall.js +++ b/src/firewall.js @@ -267,7 +267,7 @@ class Firewall extends common.ServiceObject { callback = callback || common.util.noop; metadata = metadata || {}; metadata.name = this.name; - metadata.network = this.metadata.network; + metadata.network = metadata.network || this.metadata.network; this.request( { method: 'PATCH', diff --git a/test/firewall.js b/test/firewall.js index b21ba2af..eaf5d913 100644 --- a/test/firewall.js +++ b/test/firewall.js @@ -187,8 +187,8 @@ describe('Firewall', function() { assert.strictEqual(reqOpts.uri, ''); assert.strictEqual(reqOpts.json, metadata); assert.deepStrictEqual(metadata, { - name: firewall.name, - network: FIREWALL_NETWORK, + name: FIREWALL_NAME, + network: FIREWALL_NETWORK }); done(); @@ -197,6 +197,24 @@ describe('Firewall', function() { firewall.setMetadata(metadata, assert.ifError); }); + it('should respect network specification', function(done) { + var metadata = {'network': 'custom-network'}; + + firewall.request = function(reqOpts) { + assert.strictEqual(reqOpts.method, 'PATCH'); + assert.strictEqual(reqOpts.uri, ''); + assert.strictEqual(reqOpts.json, metadata); + assert.deepStrictEqual(metadata, { + name: FIREWALL_NAME, + network: 'custom-network', + }); + + done(); + }; + + firewall.setMetadata(metadata, assert.ifError); + }) + describe('error', function() { const error = new Error('Error.'); const apiResponse = {a: 'b', c: 'd'}; From 3e228fb4fa5c4181c056d75564e4632fdc9bd6d5 Mon Sep 17 00:00:00 2001 From: Alexander Pankratov Date: Wed, 5 Sep 2018 16:08:08 +0200 Subject: [PATCH 2/3] !fixup: prettier + removing test selector --- package.json | 2 +- test/firewall.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 50cd19a8..37716f94 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "compute engine" ], "scripts": { - "cover": "nyc --reporter=lcov mocha test/*$MATCH*.js && nyc report", + "cover": "nyc --reporter=lcov mocha test/*.js && nyc report", "docs": "jsdoc -c .jsdoc.js", "generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json", "lint": "eslint '**/*.js'", diff --git a/test/firewall.js b/test/firewall.js index eaf5d913..a6154d72 100644 --- a/test/firewall.js +++ b/test/firewall.js @@ -188,7 +188,7 @@ describe('Firewall', function() { assert.strictEqual(reqOpts.json, metadata); assert.deepStrictEqual(metadata, { name: FIREWALL_NAME, - network: FIREWALL_NETWORK + network: FIREWALL_NETWORK, }); done(); @@ -198,7 +198,7 @@ describe('Firewall', function() { }); it('should respect network specification', function(done) { - var metadata = {'network': 'custom-network'}; + var metadata = {network: 'custom-network'}; firewall.request = function(reqOpts) { assert.strictEqual(reqOpts.method, 'PATCH'); @@ -213,7 +213,7 @@ describe('Firewall', function() { }; firewall.setMetadata(metadata, assert.ifError); - }) + }); describe('error', function() { const error = new Error('Error.'); From 00b62a57e901b753be9a7ee3610c72449d6a3bda Mon Sep 17 00:00:00 2001 From: Stephen Date: Wed, 21 Nov 2018 11:09:49 -0500 Subject: [PATCH 3/3] modernize --- test/firewall.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/test/firewall.js b/test/firewall.js index a6154d72..281b640c 100644 --- a/test/firewall.js +++ b/test/firewall.js @@ -47,7 +47,7 @@ describe('Firewall', function() { createFirewall: util.noop, }; const FIREWALL_NAME = 'tcp-3000'; - const FIREWALL_NETWORK = 'global/networks/default'; + const DEFAULT_FIREWALL_NETWORK = 'global/networks/default'; before(function() { Firewall = proxyquire('../src/firewall.js', { @@ -76,7 +76,9 @@ describe('Firewall', function() { }); it('should default to the global network', function() { - assert.deepStrictEqual(firewall.metadata, {network: FIREWALL_NETWORK}); + assert.deepStrictEqual(firewall.metadata, { + network: DEFAULT_FIREWALL_NETWORK, + }); }); it('should inherit from ServiceObject', function() { @@ -187,8 +189,8 @@ describe('Firewall', function() { assert.strictEqual(reqOpts.uri, ''); assert.strictEqual(reqOpts.json, metadata); assert.deepStrictEqual(metadata, { - name: FIREWALL_NAME, - network: FIREWALL_NETWORK, + name: firewall.name, + network: DEFAULT_FIREWALL_NETWORK, }); done(); @@ -198,17 +200,10 @@ describe('Firewall', function() { }); it('should respect network specification', function(done) { - var metadata = {network: 'custom-network'}; + const metadata = {network: 'custom-network'}; firewall.request = function(reqOpts) { - assert.strictEqual(reqOpts.method, 'PATCH'); - assert.strictEqual(reqOpts.uri, ''); - assert.strictEqual(reqOpts.json, metadata); - assert.deepStrictEqual(metadata, { - name: FIREWALL_NAME, - network: 'custom-network', - }); - + assert.strictEqual(reqOpts.json.network, metadata.network); done(); };