Skip to content

Commit

Permalink
feat: adding ability to specify firewall network (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
apankratov authored and JustinBeckwith committed Dec 21, 2018
1 parent bfdd0b5 commit 7f4c0e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-compute/src/firewall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 16 additions & 3 deletions packages/google-cloud-compute/test/firewall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -188,7 +190,7 @@ describe('Firewall', function() {
assert.strictEqual(reqOpts.json, metadata);
assert.deepStrictEqual(metadata, {
name: firewall.name,
network: FIREWALL_NETWORK,
network: DEFAULT_FIREWALL_NETWORK,
});

done();
Expand All @@ -197,6 +199,17 @@ describe('Firewall', function() {
firewall.setMetadata(metadata, assert.ifError);
});

it('should respect network specification', function(done) {
const metadata = {network: 'custom-network'};

firewall.request = function(reqOpts) {
assert.strictEqual(reqOpts.json.network, metadata.network);
done();
};

firewall.setMetadata(metadata, assert.ifError);
});

describe('error', function() {
const error = new Error('Error.');
const apiResponse = {a: 'b', c: 'd'};
Expand Down

0 comments on commit 7f4c0e7

Please sign in to comment.