Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

feat: adding ability to specify firewall network #150

Merged
merged 4 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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 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