|
| 1 | +var helpers = require('./../helpers'); |
| 2 | +var getMetadataServiceEndpoint = require('../../lib/metadata_service/get_metadata_service_endpoint'); |
| 3 | + |
| 4 | +var Endpoint = require('../../lib/metadata_service/endpoint'); |
| 5 | +var EndpointMode = require('../../lib/metadata_service/endpoint_mode'); |
| 6 | +var ENDPOINT_CONFIG_OPTIONS = require('../../lib/metadata_service/endpoint_config_options').ENDPOINT_CONFIG_OPTIONS; |
| 7 | + |
| 8 | +var AWS = helpers.AWS; |
| 9 | + |
| 10 | +if (AWS.util.isNode()) { |
| 11 | + describe('getMetadataServiceEndpoint', function() { |
| 12 | + describe('when endpoint is defined', function() { |
| 13 | + it('returns endpoint', function() { |
| 14 | + var mockEndpoint = 'http://127.0.0.1'; |
| 15 | + helpers.spyOn(AWS.util, 'loadConfig').andReturn(mockEndpoint); |
| 16 | + expect(getMetadataServiceEndpoint()).to.equal(mockEndpoint); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('when endpoint is not defined', function() { |
| 21 | + [ |
| 22 | + [Endpoint.IPv4, EndpointMode.IPv4], |
| 23 | + [Endpoint.IPv6, EndpointMode.IPv6], |
| 24 | + ].forEach(function([endpoint, endpointMode]) { |
| 25 | + it('returns endpoint:'+ endpoint + ' for endpointMode:' + endpointMode, function() { |
| 26 | + helpers.spyOn(AWS.util, 'loadConfig').andCallFake(function(options) { |
| 27 | + if (options === ENDPOINT_CONFIG_OPTIONS) { |
| 28 | + return undefined; |
| 29 | + } else { |
| 30 | + return endpointMode; |
| 31 | + } |
| 32 | + }); |
| 33 | + expect(getMetadataServiceEndpoint()).to.equal(endpoint); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + it('throws error for invalid endpointMode:invalid', function() { |
| 38 | + const invalidEndpointMode = 'invalid'; |
| 39 | + helpers.spyOn(AWS.util, 'loadConfig').andCallFake(function(options) { |
| 40 | + if (options === ENDPOINT_CONFIG_OPTIONS) { |
| 41 | + return undefined; |
| 42 | + } else { |
| 43 | + return invalidEndpointMode; |
| 44 | + } |
| 45 | + }); |
| 46 | + expect(function() { |
| 47 | + getMetadataServiceEndpoint(); |
| 48 | + }).to['throw']('Unsupported endpoint mode: ' + invalidEndpointMode); |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
| 52 | +} |
0 commit comments