Browse Source

Check context description in kube e2e

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 4 years ago
parent
commit
794f638bec
4 changed files with 12 additions and 9 deletions
  1. 2 1
      .github/PULL_REQUEST_TEMPLATE.md
  2. 5 5
      kube/context.go
  3. 3 3
      kube/context_test.go
  4. 2 0
      kube/e2e/compose_test.go

+ 2 - 1
.github/PULL_REQUEST_TEMPLATE.md

@@ -4,7 +4,8 @@
 <!-- If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" -->
 
 <!-- optional tests
-You can add a / mention to run tests executed by default only on main branch : 
+You can add a / mention to run tests executed by default only on main branch :
+* `test-kube` to run Kube E2E tests
 * `test-aci` to run ACI E2E tests
 * `test-ecs` to run ECS E2E tests
 * `test-windows` to run tests & E2E tests on windows

+ 5 - 5
kube/context.go

@@ -43,7 +43,7 @@ func (cp ContextParams) CreateContextData() (interface{}, string, error) {
 		// we use the current kubectl context from a $KUBECONFIG path
 		return store.KubeContext{
 			FromEnvironment: cp.FromEnvironment,
-		}, cp.Description, nil
+		}, cp.getDescription(), nil
 	}
 	user := prompt.User{}
 	selectContext := func() error {
@@ -69,7 +69,7 @@ func (cp ContextParams) CreateContextData() (interface{}, string, error) {
 				ContextName:     cp.KubeContextName,
 				KubeconfigPath:  cp.KubeConfigPath,
 				FromEnvironment: cp.FromEnvironment,
-			}, cp.Description, nil
+			}, cp.getDescription(), nil
 		}
 		err := selectContext()
 		if err != nil {
@@ -118,8 +118,8 @@ func (cp ContextParams) getDescription() string {
 		return "From environment variables"
 	}
 	configFile := "default kube config"
-	if cp.KubeconfigPath != "" {
-		configFile = cp.KubeconfigPath
+	if cp.KubeConfigPath != "" {
+		configFile = cp.KubeConfigPath
 	}
-	return fmt.Sprintf("%s (in %s)", cp.ContextName, configFile)
+	return fmt.Sprintf("%s (in %s)", cp.KubeContextName, configFile)
 }

+ 3 - 3
kube/context_test.go

@@ -43,15 +43,15 @@ func TestContextDescriptionIfProvided(t *testing.T) {
 
 func TestContextDescriptionIfConfigFile(t *testing.T) {
 	cp := ContextParams{
-		ContextName:    "my-context",
-		KubeconfigPath: "~/.kube/config",
+		KubeContextName: "my-context",
+		KubeConfigPath:  "~/.kube/config",
 	}
 	description := cp.getDescription()
 	assert.Equal(t, description, "my-context (in ~/.kube/config)")
 }
 func TestContextDescriptionIfDefaultConfigFile(t *testing.T) {
 	cp := ContextParams{
-		ContextName: "my-context",
+		KubeContextName: "my-context",
 	}
 	description := cp.getDescription()
 	assert.Equal(t, description, "my-context (in default kube config)")

+ 2 - 0
kube/e2e/compose_test.go

@@ -65,6 +65,8 @@ func TestComposeUp(t *testing.T) {
 		res := c.RunDockerCmd("context", "create", "kubernetes", "--kubeconfig", kubeconfig, "--kubecontext", kubeContextName, dockerContextName)
 		res.Assert(t, icmd.Expected{Out: fmt.Sprintf("Successfully created kube context %q", dockerContextName)})
 		c.RunDockerCmd("context", "use", dockerContextName)
+		res = c.RunDockerCmd("context", "ls")
+		res.Assert(t, icmd.Expected{Out: fmt.Sprintf("%s *      kube                %s (in %s)", dockerContextName, kubeContextName, kubeconfig)})
 	})
 
 	t.Run("up", func(t *testing.T) {