Skip to content

Commit

Permalink
Run devfile create Interation test on kubernetes cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
prietyc123 committed Apr 15, 2020
1 parent 77681be commit 0cc2060
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ env:
global:
- secure: "SSGPlBUXMb2F3ycFEvRKHoftYy0UkIprwgtfOKXU/Uc359Qct+IrF/b8GuTd64tedXtnQE4z4fxqT8wdYRdNwUysmOvRyzlNTRhs1gocx5iL5El8+7F4we7wElh6ckt2Z5AVI5g0JOwYeQNURFhgDumN14K8XsOu7a2LzRBVFRn55z79xgTL+JnTI89JIWjz1QCr8Z054CMaK0MHJRLkgPnbnx1Skra3Wt16g29wRZLqLWoU8lyrLy9Ao/yHw/AJMCNie8ah7nNiOEdgPTcr/onZ/v+eVyaTvzE9UrmdeqpUpASypAAUnmZ9Q6QsU31dVxwbfPB0r8TzrqinCOYMnHbU/3fIz49Q+yv7RyifYsTlnx7+J79LmCvs7X+iKkmOprWdBRwUUxzDhwgIGnmBlYf0nKj9H2U3XFCYDnbRSI9ZugGBprs3t09w15gwq/wLM6DhY87zNhM4Vfb34ZXVBCEhtUXKUVbVthiPOWlHtbs0YympG/QCV+27tVIszgek8FFt6/fJeEh/APNadK9fuU01ozB01aXj0xMl3PlvoWWeQXDnyttHEWRaiVpbPKGoV5a7LPCVpWk5EOX8YNgHEUnjKwfzVBUriXAd+8zp0sx6TRdt1ts7x04NP1yFF1SCXXBpz/geOsfa2bBQyJx6y7CODcmW7fbcJLxmwdGlm6E="
- secure: "Tr9KxWvfQS6BSF1qUqz1Q41le5k/c+L37Aq8wTPQcmXVu8nLv5T1QMarx64KfZ2qaQBRV+M6DwnJQM7HU/cWX9AKpdoAO2INqANfoFLh8XTR5ncHjaNTzi9aS7owxa+9t0yfKowq7s4dp96nqmwchYFtUxpzKo0TMOcQ1l1AGEu5liniXb9VOKgG8UAZsLgD6b2a80nn6NP1JehGGxcWsow0EzxalnJ8Cv78YTLmqGNowYh5UmkhjkxqE4TskQafRd2qtYMPvxnC2CFd8G3qMlbBzCxM02lGKwbr/Vi41hcSyD3uuyaKVHr/g5qLcp/HNyrUGTREL1UvWkWjlL6ovuh6uHYlnpVwQkX5fzUH7z2hlr9HjQ3Tu6Sbh1CX5QBR5PUkvoOfdx0BHTmTTw2xkvUDHarqZT1OkMuUplCY/VMnJaqa5ko126r8CyKYqRoT4HQuqa6szVawGiB211VCQXJRVyLYtKUGO6mmnMUoi5H676/sv6c9py8bieMoyEyrI87lS0AhQ6QLnTjNbEO5xt6vFi7rEgcctD5nuEBwb/X2bmM2OdZFYXrIbXaZfq7fRKyzCQthfceCmySExOGI9ndCE/mS68X6NNFBVsVwb7zt0zSY6oGlf0/N2CR5sf8gwKYG1scr5Jyqmuifvqv433zepA0Sxj6WqC3ixlssNd8="
- MINIKUBE_WANTUPDATENOTIFICATION=false
- MINIKUBE_WANTREPORTERRORPROMPT=false
- MINIKUBE_HOME=$HOME
- CHANGE_MINIKUBE_NONE_USER=true
- KUBECONFIG=$HOME/.kube/config
jobs:
include:
# YAML alias, for settings shared across the tests
Expand Down Expand Up @@ -140,4 +145,26 @@ jobs:
- travis_wait make test-e2e-images
- odo logout

# Run devfile integration test on Kubernetes cluster
- <<: *base-test
stage: test
name: "devfile catalog, create command integration tests"
before_script:
# Download kubectl, a cli tool for accessing Kubernetes cluster
- curl -sLo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.7.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Download minikube and set up Kubernetes single node cluster
- curl -sLo minikube https://storage.googleapis.com/minikube/releases/v0.25.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- mkdir -p $HOME/.kube $HOME/.minikube
- touch $KUBECONFIG
- sudo minikube start --vm-driver=none --kubernetes-version=v1.7.0
- minikube update-context
- "sudo chown -R travis: /home/travis/.minikube/"
script:
- kubectl cluster-info
- make bin
- sudo cp odo /usr/bin
- export KUBERNETES=true
- travis_wait make test-cmd-devfile-catalog
- travis_wait make test-cmd-devfile-create


25 changes: 25 additions & 0 deletions tests/helper/kubernetes_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package helper

import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

// CreateRandNamespace create new project with random name in kubernetes cluster (10 letters)
func CreateRandNamespace(context string) string {
projectName := RandString(10)
fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName)
CmdShouldPass("kubectl", "create", "namespace", projectName)
CmdShouldPass("kubectl", "config", "set-context", context, "--namespace", projectName)
session := CmdShouldPass("kubectl", "get", "namespaces")
Expect(session).To(ContainSubstring(projectName))
return projectName
}

// DeleteNamespace deletes a specified project in kubernetes cluster
func DeleteNamespace(projectName string) {
fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName)
CmdShouldPass("kubectl", "delete", "namespaces", projectName)
}
23 changes: 12 additions & 11 deletions tests/integration/devfile/cmd_devfile_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,59 @@ var _ = Describe("odo devfile create command tests", func() {
// This is run after every Spec (It)
var _ = BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
project = helper.CreateRandProject()
context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
if os.Getenv("KUBERNETES") == "true" {
project = helper.CreateRandNamespace(context)
} else {
project = helper.CreateRandProject()
}
currentWorkingDirectory = helper.Getwd()
helper.Chdir(context)
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
})

// This is run after every Spec (It)
var _ = AfterEach(func() {
helper.DeleteProject(project)
if os.Getenv("KUBERNETES") == "true" {
helper.DeleteNamespace(project)
} else {
helper.DeleteProject(project)
}
helper.Chdir(currentWorkingDirectory)
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
})

Context("When executing odo create with devfile component type argument", func() {
It("should successfully create the devfile component", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
helper.CmdShouldPass("odo", "create", "openLiberty")
})
})

Context("When executing odo create with devfile component type and component name arguments", func() {
It("should successfully create the devfile component", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
componentName := helper.RandString(6)
helper.CmdShouldPass("odo", "create", "openLiberty", componentName)
})
})

Context("When executing odo create with devfile component type argument and --project flag", func() {
It("should successfully create the devfile component", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
componentNamespace := helper.RandString(6)
helper.CmdShouldPass("odo", "create", "openLiberty", "--project", componentNamespace)
})
})

Context("When executing odo create with devfile component type argument and --namespace flag", func() {
It("should successfully create the devfile component", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
componentNamespace := helper.RandString(6)
helper.CmdShouldPass("odo", "create", "openLiberty", "--namespace", componentNamespace)
})
})

Context("When executing odo create with devfile component name that contains unsupported character", func() {
It("should failed with component name is not valid and prompt supported character", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
componentName := "BAD@123"
output := helper.CmdShouldFail("odo", "create", "openLiberty", componentName)
helper.MatchAllInOutput(output, []string{"Contain only lowercase alphanumeric characters or ‘-’"})
Expand All @@ -75,7 +79,6 @@ var _ = Describe("odo devfile create command tests", func() {

Context("When executing odo create with devfile component name that contains all numeric values", func() {
It("should failed with component name is not valid and prompt container name must not contain all numeric values", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
componentName := "123456"
output := helper.CmdShouldFail("odo", "create", "openLiberty", componentName)
helper.MatchAllInOutput(output, []string{"Must not contain all numeric values"})
Expand All @@ -84,7 +87,6 @@ var _ = Describe("odo devfile create command tests", func() {

Context("When executing odo create with devfile component name that contains more than 63 characters ", func() {
It("should failed with component name is not valid and prompt container name contains at most 63 characters", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
componentName := helper.RandString(64)
output := helper.CmdShouldFail("odo", "create", "openLiberty", componentName)
helper.MatchAllInOutput(output, []string{"Contain at most 63 characters"})
Expand All @@ -93,7 +95,6 @@ var _ = Describe("odo devfile create command tests", func() {

Context("When executing odo create with an invalid devfile component", func() {
It("should fail with please run 'odo catalog list components'", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
fakeComponentName := "fake-component"
output := helper.CmdShouldFail("odo", "create", fakeComponentName)
expectedString := "\"" + fakeComponentName + "\" not found"
Expand Down

0 comments on commit 0cc2060

Please sign in to comment.