Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: Added test cases for Virtual Networks #595

Merged
merged 1 commit into from
Mar 24, 2021
Merged
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
138 changes: 138 additions & 0 deletions plugins/azure/virtualnetworks/multipleSubnets.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
var expect = require('chai').expect;
var multipleSubnets = require('./multipleSubnets');

const listVnets = [
{
"name": "cloudsplit-vnet",
"id": "/subscriptions/123/resourceGroups/aqua-rg/providers/Microsoft.Network/virtualNetworks/cloudsplit-vnet",
"type": "Microsoft.Network/virtualNetworks",
"subnets": [
{
"name": "default",
"id": "/subscriptions/123/resourceGroups/aqua-rg/providers/Microsoft.Network/virtualNetworks/cloudsplit-vnet/subnets/default",
"type": "Microsoft.Network/virtualNetworks/subnets"
},
{
"name": "default1",
"id": "/subscriptions/123/resourceGroups/aqua-rg/providers/Microsoft.Network/virtualNetworks/cloudsplit-vnet/subnets/default",
"type": "Microsoft.Network/virtualNetworks/subnets"
}
]
},
{
"name": "cloudsplit-vnet",
"id": "/subscriptions/123/resourceGroups/aqua-rg/providers/Microsoft.Network/virtualNetworks/cloudsplit-vnet",
"type": "Microsoft.Network/virtualNetworks",
"subnets": [
{
"name": "default",
"id": "/subscriptions/123/resourceGroups/aqua-rg/providers/Microsoft.Network/virtualNetworks/cloudsplit-vnet/subnets/default",
"type": "Microsoft.Network/virtualNetworks/subnets"
}
]
},
{
"name": "cloudsplit-vnet",
"id": "/subscriptions/123/resourceGroups/aqua-rg/providers/Microsoft.Network/virtualNetworks/cloudsplit-vnet",
"type": "Microsoft.Network/virtualNetworks",
"subnets": []
}
];

const createCache = (vnets, err) => {
return {
virtualNetworks: {
listAll: {
'eastus': {
err: err,
data: vnets
}
}
}
}
};

describe('multipleSubnets', function() {
describe('run', function() {
it('should give passing result if No existing Virtual Networks found', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No existing Virtual Networks found');
expect(results[0].region).to.equal('eastus');
done()
};

const cache = createCache(
[]
);

multipleSubnets.run(cache, {}, callback);
});

it('should give failing result if only one subnet in the Virtual Network is used', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('Only one subnet in the Virtual Network is used');
expect(results[0].region).to.equal('eastus');
done()
};

const cache = createCache(
[listVnets[1]]
);

multipleSubnets.run(cache, {}, callback);
});

it('should give passing result if there are more than one subnets in Virtual Network', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('different subnets used in the Virtual Network');
expect(results[0].region).to.equal('eastus');
done()
};

const cache = createCache(
[listVnets[0]]
);

multipleSubnets.run(cache, {}, callback);
});

it('should give passing result if the Virtual Network does not have any subnets', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('The Virtual Network does not have any subnets');
expect(results[0].region).to.equal('eastus');
done()
};

const cache = createCache(
[listVnets[2]]
);

multipleSubnets.run(cache, {}, callback);
});

it('should give unknown result if unable to query for Virtual Networks', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
expect(results[0].message).to.include('Unable to query for Virtual Networks');
expect(results[0].region).to.equal('eastus');
done()
};

const cache = createCache(
listVnets,
{ message: 'unable to query Virtual Networks'}
);

multipleSubnets.run(cache, {}, callback);
});
})
})