Exemple #1
0
        public void ShouldResolveImageTagWhenImageNameIsNotSet()
        {
            var date = DateTimeOffset.UtcNow.AddHours(-1);
            var dockerRunLine = DockerRunParamsBuilder.BuildDockerLogLine(
                "testContainer",
                ":1.0",
                "test-services",
                "test",
                date,
                42.ToString(),
                4242.ToString()).AsSpan();

            var dockerRunParameters = LogExtractor.Extract(dockerRunLine);

            Assert.Empty(dockerRunParameters.ImageName.ToString());
            Assert.Equal("1.0", dockerRunParameters.ImageTag.ToString());
        }
Exemple #2
0
        public void ShouldHaveEmptyContainerOrServiceNameWhenNotProvided()
        {
            var date = DateTimeOffset.UtcNow.AddHours(-1);
            var dockerRunLine = DockerRunParamsBuilder.BuildDockerLogLine(
                null,
                "test:1.0",
                null,
                "test",
                date,
                42.ToString(),
                4242.ToString()).AsSpan();

            var dockerRunParameters = LogExtractor.Extract(dockerRunLine);

            Assert.Empty(dockerRunParameters.ContainerName.ToString());
            Assert.Empty(dockerRunParameters.ServiceName.ToString());
        }
Exemple #3
0
        public void ShouldHaveEmptyImageAndTagWhenTheyAreNotProvided()
        {
            var date = DateTimeOffset.UtcNow.AddHours(-1);
            var dockerRunLine = DockerRunParamsBuilder.BuildDockerLogLine(
                "testContainer",
                null,
                "test-services",
                "test",
                date,
                42.ToString(),
                4242.ToString()).AsSpan();

            var dockerRunParameters = LogExtractor.Extract(dockerRunLine);

            Assert.Empty(dockerRunParameters.ImageName.ToString());
            Assert.Empty(dockerRunParameters.ImageTag.ToString());
        }
Exemple #4
0
        public void ShouldResolveOutboundPortOnly()
        {
            var date = DateTimeOffset.UtcNow.AddHours(-1);
            var dockerRunLine = DockerRunParamsBuilder.BuildDockerLogLine(
                "testContainer",
                "test:1.0:invalidTag",
                "test-services",
                "test",
                date,
                string.Empty,
                42.ToString()).AsSpan();

            var dockerRunParameters = LogExtractor.Extract(dockerRunLine);

            Assert.Equal(-1, dockerRunParameters.InboundPort);
            Assert.Equal(42, dockerRunParameters.OutboundPort);
        }
Exemple #5
0
        public void ShouldReturnNegativeOneWhenPortsDontHaveNumericValues()
        {
            var date = DateTimeOffset.UtcNow.AddHours(-1);
            var dockerRunLine = DockerRunParamsBuilder.BuildDockerLogLine(
                "testContainer",
                "test:1.0:invalidTag",
                "test-services",
                "test",
                date,
                null,
                "not-a-number").AsSpan();

            var dockerRunParameters = LogExtractor.Extract(dockerRunLine);

            Assert.Equal(-1, dockerRunParameters.InboundPort);
            Assert.Equal(-1, dockerRunParameters.OutboundPort);
        }
Exemple #6
0
        public Task <ExtractDockerRunParamsResponse> Handle(ExtractDockerRunParamsRequest request, CancellationToken cancellationToken)
        {
            _logger.LogDebug(LogDockerLogLineReceived, request.LogLine);

            var metadata = LogExtractor.Extract(request.LogLine);

            return(Task.FromResult(
                       new ExtractDockerRunParamsResponse
            {
                ServiceName = metadata.ServiceName.ToString(),
                ContainerName = metadata.ContainerName.ToString(),
                ImageName = metadata.ImageName.ToString(),
                ImageTag = metadata.ImageTag.ToString(),
                InboundPort = metadata.InboundPort.ToString(),
                OutboundPort = metadata.OutboundPort.ToString(),
                EventDate = metadata.Date
            }));
        }
Exemple #7
0
        public void ShouldExtractCorrectParameters()
        {
            var date = DateTimeOffset.UtcNow.AddHours(-1);
            var dockerRunLine = DockerRunParamsBuilder.BuildDockerLogLine(
                "testContainer",
                "test:1.0",
                "test-service",
                "test",
                date,
                42.ToString(),
                4242.ToString()).AsSpan();

            var dockerRunParameters = LogExtractor.Extract(dockerRunLine);

            Assert.Equal("testContainer", dockerRunParameters.ContainerName.ToString());
            Assert.Equal("test", dockerRunParameters.ImageName.ToString());
            Assert.Equal("1.0", dockerRunParameters.ImageTag.ToString());
            Assert.Equal("test-service", dockerRunParameters.ServiceName.ToString());
            Assert.Equal(42, dockerRunParameters.InboundPort);
            Assert.Equal(4242, dockerRunParameters.OutboundPort);
            Assert.Equal(date, dockerRunParameters.Date);
        }
Exemple #8
0
 public void Extract2()
 {
     _ = LogExtractor.Extract(Data);
 }