Example #1
0
        public void AddECSContainerSupport_does_nothing_if_no_ECS_metadata_file_key_available(IServiceCollection services, IConfiguration configuration)
        {
            Environment.SetEnvironmentVariable(EMG.Extensions.Configuration.ECSMetadataExtensions.ECSContainerMetadataFileKey, null);

            ECSMetadataExtensions.AddECSContainerSupport(services, configuration);

            Mock.Get(services).Verify(p => p.Add(It.IsAny <ServiceDescriptor>()), Times.Never);
        }
Example #2
0
        public void AddECSContainerSupport_configures_AnnouncementServiceOptions(IServiceCollection services, IConfiguration configuration)
        {
            AddFakeContainerMetadataFileKey();

            ECSMetadataExtensions.AddECSContainerSupport(services, configuration);

            Mock.Get(services).Verify(p => p.Add(It.Is <ServiceDescriptor>(sd => sd.ServiceType == typeof(IConfigureOptions <AnnouncementServiceOptions>))));
        }
Example #3
0
        public void AddECSContainerSupport_configuration_throws_if_endpoint_has_no_address(ServiceCollection services, IConfiguration configuration, ServiceEndpoint endpoint)
        {
            AddFakeContainerMetadataFileKey();

            ECSMetadataExtensions.AddECSContainerSupport(services, configuration);

            var serviceProvider = services.BuildServiceProvider();

            var options = serviceProvider.GetRequiredService <IOptions <AnnouncementServiceOptions> >();

            Assert.Throws <ArgumentNullException>(() => options.Value.EndpointDiscoveryMetadata(endpoint));
        }
Example #4
0
        public void AddECSContainerSupport_configuration_returns_metadata_with_same_if_no_mapping(ServiceCollection services, [Frozen] ECSContainerMetadata containerMetadata, IConfiguration configuration, ServiceEndpoint endpoint, int port, string address)
        {
            AddFakeContainerMetadataFileKey();

            var expectedAddress = new Uri($"http://{containerMetadata.HostPrivateIPv4Address}:{port}/{address}");

            endpoint.Address = new EndpointAddress($"http://localhost:{port}/{address}");

            ECSMetadataExtensions.AddECSContainerSupport(services, configuration);

            var serviceProvider = services.BuildServiceProvider();

            var options = serviceProvider.GetRequiredService <IOptions <AnnouncementServiceOptions> >();

            var result = options.Value.EndpointDiscoveryMetadata(endpoint);

            Assert.That(result.Address.Uri, Is.EqualTo(expectedAddress).IgnoreCase);
        }
Example #5
0
        public void AddECSContainerSupport_configuration_returns_metadata_with_same_address_when_ecs_metadata_has_no_ipv4_address(ServiceCollection services, IConfiguration configuration, ServiceEndpoint endpoint, int port, string address)
        {
            AddFakeContainerMetadataFileKey();

            configuration[nameof(ECSContainerMetadata.HostPrivateIPv4Address)] = null;

            endpoint.Address = new EndpointAddress($"http://localhost:{port}/{address}");

            ECSMetadataExtensions.AddECSContainerSupport(services, configuration);

            var serviceProvider = services.BuildServiceProvider();

            var options = serviceProvider.GetRequiredService <IOptions <AnnouncementServiceOptions> >();

            var result = options.Value.EndpointDiscoveryMetadata(endpoint);

            Assert.That(result.Address.Uri, Is.EqualTo(endpoint.Address.Uri));
        }