public async Task TestGetKubectlContextForClusterAsync_RunsCommandAgainstExpectedZone() { const string expectedZone = "expected-zone"; await KubectlContext.GetForClusterAsync(DefaultCluster, expectedZone); VerifyCommandArgsContain($"--zone={expectedZone}"); }
public async Task TestDispose_NonReentrant() { _objectUnderTest = await KubectlContext.GetForClusterAsync(DefaultCluster, DefaultZone); _objectUnderTest.Dispose(); _objectUnderTest.Dispose(); PackageMock.Verify(p => p.GetMefService <IFileSystem>().File.Delete(It.IsAny <string>()), Times.Once); }
public async Task TestGetKubectlContextForClusterAsync_ThrowsOnCommandFailure() { SetupRunCommandResult(false); GCloudException e = await Assert.ThrowsExceptionAsync <GCloudException>( () => KubectlContext.GetForClusterAsync(ExpectedCluster, DefaultZone)); StringAssert.Contains(e.Message, ExpectedCluster); }
public async Task TestGetKubectlContextForClusterAsync_RunsCommandWithKubeConfigEnvVar() { IDictionary <string, string> environment = new Dictionary <string, string>(); SetupRunCommandGetEnvironment(commandEnvironment => environment = commandEnvironment); await KubectlContext.GetForClusterAsync(DefaultCluster, DefaultZone); Assert.IsTrue(environment.ContainsKey(KubectlContext.KubeConfigVariable)); }
public async Task TestGetKubectlContextForClusterAsync_RunsCommandWithExpectedUseDefaultCredentialsEnvVar() { IDictionary <string, string> environment = new Dictionary <string, string>(); SetupRunCommandGetEnvironment(commandEnvironment => environment = commandEnvironment); await KubectlContext.GetForClusterAsync(DefaultCluster, DefaultZone); Assert.AreEqual( KubectlContext.TrueValue, environment[KubectlContext.UseApplicationDefaultCredentialsVariable]); }
public async Task TestGetKubectlContextForClusterAsync_RunsCommandWithExpectedGoogleCredentialsEnvVar() { const string expectedCredentialsPath = "expected-credentials-path"; CredentialStoreMock.Setup(cs => cs.CurrentAccountPath).Returns(expectedCredentialsPath); IDictionary <string, string> environment = new Dictionary <string, string>(); SetupRunCommandGetEnvironment(commandEnvironment => environment = commandEnvironment); await KubectlContext.GetForClusterAsync(DefaultCluster, DefaultZone); Assert.AreEqual(expectedCredentialsPath, environment[KubectlContext.GoogleApplicationCredentialsVariable]); }
public async Task TestDispose_DeletesConfigPath() { IDictionary <string, string> environment = new Dictionary <string, string>(); SetupRunCommandGetEnvironment(commandEnvironment => environment = commandEnvironment); _objectUnderTest = await KubectlContext.GetForClusterAsync(DefaultCluster, DefaultZone); _objectUnderTest.Dispose(); string expectedDeletePath = environment[KubectlContext.KubeConfigVariable]; PackageMock.Verify(p => p.GetMefService <IFileSystem>().File.Delete(expectedDeletePath)); }
public async Task BeforeEachAsync() { _processServiceMock = new Mock <IProcessService>(); PackageMock.Setup(p => p.ProcessService).Returns(_processServiceMock.Object); _kubeConfigPath = null; SetupRunCommandGetEnvironment( defaultInitKubectlEnvironment => _kubeConfigPath = _kubeConfigPath ?? defaultInitKubectlEnvironment[KubectlContext.KubeConfigVariable]); _objectUnderTest = await KubectlContext.GetForClusterAsync(DefaultCluster, DefaultZone); _mockedOutputAction = Mock.Of <Action <string> >(); }
public DeploymentOptions( KubectlContext context, string deploymentName, string deploymentVersion, bool exposeService, bool exposePublicService, string configuration, int replicas) { KubectlContext = context; DeploymentName = deploymentName; DeploymentVersion = deploymentVersion; ExposeService = exposeService; ExposePublicService = exposePublicService; Configuration = configuration; Replicas = replicas; }
public async Task BeforeEachAsync() { _processServiceMock = new Mock <IProcessService>(); PackageMock.Setup(p => p.ProcessService).Returns(_processServiceMock.Object); _fileSystemMock = new Mock <IFileSystem> { DefaultValueProvider = DefaultValueProvider.Mock }; _kubeConfigPath = Path.GetTempFileName(); _fileSystemMock.Setup(fs => fs.Path.GetTempFileName()).Returns(_kubeConfigPath); _processServiceMock.SetupRunCommandAsync().ReturnsResult(true); _objectUnderTest = new KubectlContext( _fileSystemMock.Object, _processServiceMock.ToLazy(), CredentialsStore.Default); await _objectUnderTest.InitClusterCredentialsAsync(s_defaultCluster); _mockedOutputAction = Mock.Of <Func <string, Task> >(); }
private static async Task <string> WaitForServicePublicIpAddressAsync(string name, Action waitingCallback, KubectlContext kubectlContext) { DateTime start = DateTime.Now; TimeSpan actualTime = DateTime.Now - start; while (actualTime < s_newServiceIpTimeout) { waitingCallback(); var service = await KubectlWrapper.GetServiceAsync(name, kubectlContext); var ingress = service?.Status?.LoadBalancer?.Ingress?.FirstOrDefault(); if (ingress != null) { string ipAddress = null; if (ingress.TryGetValue("ip", out ipAddress)) { Debug.WriteLine($"Found service IP address: {ipAddress}"); return(ipAddress); } } Debug.WriteLine("Waiting for service to be public."); await Task.Delay(s_pollingDelay); actualTime = DateTime.Now - start; } Debug.WriteLine("Timeout while waiting for the ip address."); return(null); }
private static async Task <string> WaitForServiceClusterIpAddressAsync(string name, KubectlContext context) { var service = await KubectlWrapper.GetServiceAsync(name, context); return(service?.Spec?.ClusterIp); }
private static async Task <string> WaitForServicePublicIpAddressAsync(string name, KubectlContext kubectlContext) { DateTime start = DateTime.Now; TimeSpan actualTime = DateTime.Now - start; while (actualTime < s_newServiceIpTimeout) { GcpOutputWindow.Default.OutputLine(Resources.GkePublishWaitingForServiceIpMessage); var service = await kubectlContext.GetServiceAsync(name); var ingress = service?.Status?.LoadBalancer?.Ingress?.FirstOrDefault(); if (ingress != null && ingress.TryGetValue("ip", out string ipAddress)) { Debug.WriteLine($"Found service IP address: {ipAddress}"); return(ipAddress); } Debug.WriteLine("Waiting for service to be public."); await Task.Delay(s_pollingDelay); actualTime = DateTime.Now - start; } Debug.WriteLine("Timeout while waiting for the ip address."); return(null); }
public async Task TestGetKubectlContextForClusterAsync_RunsCommandAgainstExpectedCluster() { await KubectlContext.GetForClusterAsync(ExpectedCluster, DefaultZone); VerifyCommandArgsContain(ExpectedCluster); }
public async Task TestGetKubectlContextForClusterAsync_RunsGcloudContainerClustersGetCredentials() { await KubectlContext.GetForClusterAsync(DefaultCluster, DefaultZone); VerifyCommandArgsContain("gcloud container clusters get-credentials"); }