Пример #1
0
        public async Task BuildServiceOperator_Feedback_Async()
        {
            var builder  = FakeOperators.BuildServiceOperator(this.host.Services);
            var feedback = Assert.Single(builder.FeedbackLoops);

            var context = new ChildOperatorContext <WebDriverSession, V1Service>(
                new WebDriverSession()
            {
                Status = new WebDriverSessionStatus(),
            },
                new V1Service()
            {
            },
                this.host.Services);

            var result = await feedback(context, default).ConfigureAwait(false);

            Assert.Collection(
                result.ParentFeedback.Operations,
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/serviceReady", o.path);
                Assert.Equal(true, o.value);
            });
            Assert.Null(result.ChildFeedback);
        }
Пример #2
0
        public async Task BuildPodOperator_NoFeedback_Async(ChildOperatorContext <WebDriverSession, V1Pod> context)
        {
            var builder  = FakeOperators.BuildPodOperator(this.host.Services);
            var feedback = Assert.Single(builder.FeedbackLoops);

            Assert.Null(await feedback(context, default).ConfigureAwait(false));
        }
Пример #3
0
        public async Task ConnectsDevice_Async()
        {
            var builder      = UIAutomatorOperators.BuildPodOperator(this.host.Services);
            var feedbackLoop = Assert.Single(builder.FeedbackLoops);

            var session = new WebDriverSession()
            {
                Spec = new WebDriverSessionSpec()
                {
                    Capabilities = "{}",
                    DeviceHost   = "1.2.3.4",
                },
            };

            var pod = new V1Pod()
            {
                Status = new V1PodStatus()
                {
                    Phase             = "Running",
                    ContainerStatuses = new V1ContainerStatus[] { },
                },
            };

            var adbStream = new Mock <Stream>();

            this.kubernetes
            .Setup(c => c.ConnectToPodPortAsync(pod, 5037, It.IsAny <CancellationToken>()))
            .ReturnsAsync(adbStream.Object);

            var context = new ChildOperatorContext <WebDriverSession, V1Pod>(
                parent: session,
                child: pod,
                this.host.Services);

            this.adbClient
            .Setup(c => c.ConnectDeviceAsync(new DnsEndPoint("1.2.3.4", 5555), default))
            .Returns(Task.CompletedTask)
            .Verifiable();

            this.adbClient
            .Setup(c => c.GetDevicesAsync(default))
Пример #4
0
        public async Task BuildPodOperator_FeedbackFails_Async()
        {
            var builder  = FakeOperators.BuildPodOperator(this.host.Services);
            var feedback = Assert.Single(builder.FeedbackLoops);

            var context = new ChildOperatorContext <WebDriverSession, V1Pod>(
                new WebDriverSession()
            {
                Spec = new WebDriverSessionSpec()
                {
                    Capabilities = "{}",
                },
                Status = new WebDriverSessionStatus(),
            },
                new V1Pod()
            {
                Status = new V1PodStatus()
                {
                    Phase             = "Running",
                    ContainerStatuses = new V1ContainerStatus[] { },
                },
            },
                this.host.Services);

            var response = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.InternalServerError,
                Content    = new StringContent(@"{value:{'error':'session not created','message':'implementation defined','stacktrace':'stacktrace','data':'data'}}"),
            };

            var handler = new Mock <HttpClientHandler>();

            handler
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(response)
            .Verifiable();

            var client = new HttpClient(handler.Object);

            client.BaseAddress = new Uri("http://webdriver/");

            this.kubernetes.Setup(
                k => k.CreatePodHttpClient(context.Child, 4774))
            .Returns(client);

            var result = await feedback(context, default).ConfigureAwait(false);

            Assert.Collection(
                result.ParentFeedback.Operations,
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/error", o.path);
                Assert.Equal("session not created", o.value);
            },
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/message", o.path);
                Assert.Equal("implementation defined", o.value);
            },
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/stacktrace", o.path);
                Assert.Equal("stacktrace", o.value);
            },
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/data", o.path);

                // Data can be an arbitrary object, so a string is serialized with quotes.
                Assert.Equal("\"data\"", o.value);
            });
            Assert.Null(result.ChildFeedback);

            handler.Verify();
        }
Пример #5
0
        public async Task BuildPodOperator_FeedbackSucceeds_Async()
        {
            var builder  = FakeOperators.BuildPodOperator(this.host.Services);
            var feedback = Assert.Single(builder.FeedbackLoops);

            var context = new ChildOperatorContext <WebDriverSession, V1Pod>(
                new WebDriverSession()
            {
                Spec = new WebDriverSessionSpec()
                {
                    Capabilities = "{}",
                },
            },
                new V1Pod()
            {
                Status = new V1PodStatus()
                {
                    Phase             = "Running",
                    ContainerStatuses = new V1ContainerStatus[] { },
                },
            },
                this.host.Services);

            var response = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(@"{value:{'sessionId':'1','capabilities':{}}}"),
            };

            var handler = new Mock <HttpClientHandler>();

            handler
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(response)
            .Verifiable();

            var client = new HttpClient(handler.Object);

            client.BaseAddress = new Uri("http://webdriver/");

            this.kubernetes.Setup(
                k => k.CreatePodHttpClient(context.Child, 4774))
            .Returns(client);

            var result = await feedback(context, default).ConfigureAwait(false);

            Assert.Collection(
                result.ParentFeedback.Operations,
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status", o.path);
            },
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/sessionId", o.path);
                Assert.Equal("1", o.value);
            },
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/sessionReady", o.path);
                Assert.Equal(true, o.value);
            },
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/sessionPort", o.path);
                Assert.Equal(4774, o.value);
            },
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/capabilities", o.path);
                Assert.Equal("{}", o.value);
            });
            Assert.Null(result.ChildFeedback);

            handler.Verify();
        }