Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
wip: working
Browse files Browse the repository at this point in the history
  • Loading branch information
mpereira committed Oct 18, 2019
1 parent fa5bc2d commit 1eff034
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 335 deletions.
4 changes: 2 additions & 2 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ readonly CONTAINER_VENDOR_DIRECTORY="${CONTAINER_PROJECT_DIRECTORY}/shared/vendo

docker run \
--rm \
-e "KUBECONFIG=${CONTAINER_KUBECONFIG}" \
-e "KUBECTL_PATH=${CONTAINER_VENDOR_DIRECTORY}/kubectl.sh" \
-e "KUBECONFIG=${CONTAINER_KUBECONFIG}" \
-e "KUBECTL_PATH=${CONTAINER_VENDOR_DIRECTORY}/kubectl.sh" \
-e "DS_KUDO_VERSION=v${KUDO_VERSION}" \
-e "OPERATOR_DIRECTORY=${CONTAINER_OPERATOR_DIRECTORY}" \
-e "VENDOR_DIRECTORY=${CONTAINER_VENDOR_DIRECTORY}" \
Expand Down
7 changes: 3 additions & 4 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ go 1.13
require (
github.com/avast/retry-go v2.4.1+incompatible
github.com/gogo/protobuf v1.3.1 // indirect
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/jmcvetta/randutil v0.0.0-20150817122601-2bb1b664bcff
github.com/json-iterator/go v1.1.7 // indirect
github.com/kudobuilder/kudo v0.7.4
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8
k8s.io/apimachinery v0.0.0-20190704094520-6f131bee5e2c
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
)
134 changes: 3 additions & 131 deletions tests/go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ else
fi

# https://github.com/golang/go/wiki/Modules.
export GO111MODULE=on
# FIXME(mpereira): is this necessary? Leaving it commented for now.
# export GO111MODULE=on

# Give more priority to vendored executables.
export PATH=${VENDOR_DIRECTORY}:${PATH}
Expand Down
197 changes: 0 additions & 197 deletions tests/suites/end_to_end_test.go

This file was deleted.

68 changes: 68 additions & 0 deletions tests/suites/simple_install_uninstall_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package suites

import (
"fmt"
"os"
"testing"

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

// log "github.com/sirupsen/logrus"

kubectl "github.com/mesosphere/kudo-cassandra-operator/tests/utils/kubectl"
k8s "github.com/mesosphere/kudo-cassandra-operator/tests/utils/k8s"
kudo "github.com/mesosphere/kudo-cassandra-operator/tests/utils/kudo"
)

var (
TestName = "simple-install-uninstall-test"
OperatorName = "cassandra"
TestNamespace = fmt.Sprintf("%s-namespace", TestName)
TestInstance = "cassandra-instance"
KubeConfigPath = os.Getenv("KUBECONFIG")
KubectlPath = os.Getenv("KUBECTL_PATH")
KubectlOptions = kubectl.NewKubectlOptions(
KubectlPath,
KubeConfigPath,
TestNamespace,
"",
)
OperatorDirectory = os.Getenv("OPERATOR_DIRECTORY")
)

var _ = Describe("Simple install and uninstall test", func() {
It("Installs the operator from a directory", func() {
// TODO: Assert that it isn't running.
kudo.InstallOperatorFromDirectory(
KubectlOptions, OperatorDirectory, TestNamespace, TestInstance, []string{},
)
// TODO: Assert that it is running.
})
It("Uninstalls the operator", func() {
kudo.UninstallOperator(
KubectlOptions, OperatorName, TestNamespace, TestInstance,
)
// TODO: Assert that it isn't running.
})
})

var _ = BeforeSuite(func() {
kudo.UninstallOperator(
KubectlOptions, OperatorName, TestNamespace, TestInstance,
)
k8s.CreateNamespace(KubectlOptions, TestNamespace)
})

var _ = AfterSuite(func() {
k8s.DeleteNamespace(KubectlOptions, TestNamespace)
})

func TestService(t *testing.T) {
RegisterFailHandler(Fail)
junitReporter := reporters.NewJUnitReporter(fmt.Sprintf(
"%s-junit.xml", TestName,
))
RunSpecsWithDefaultAndCustomReporters(t, TestName, []Reporter{junitReporter})
}
1 change: 1 addition & 0 deletions tests/suites/suites.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package suites
59 changes: 59 additions & 0 deletions tests/utils/k8s/k8s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package k8s

import (
"fmt"

. "github.com/mesosphere/kudo-cassandra-operator/tests/utils/kubectl"

log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func CreateNamespace(options *KubectlOptions, namespaceName string) error {
clientset, err := GetKubernetesClientFromOptions(options)
if err != nil {
return err
}

namespace := corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespaceName,
},
}

log.Info(fmt.Sprintf("Creating namespace '%s'", namespaceName))
_, err = clientset.CoreV1().Namespaces().Create(&namespace)

if err != nil {
if apierrors.IsAlreadyExists(err) {
log.Info(fmt.Sprintf("Namespace '%s' already exists, skipping", namespaceName))
} else {
log.Info(fmt.Sprintf("Error creating namespace '%s'", namespaceName))
}
} else {
log.Info(fmt.Sprintf("Created namespace '%s'", namespaceName))
}
return err
}

func DeleteNamespace(options *KubectlOptions, namespaceName string) error {
clientset, err := GetKubernetesClientFromOptions(options)
if err != nil {
return err
}

log.Info(fmt.Sprintf("Deleting namespace '%s'", namespaceName))
err = clientset.CoreV1().Namespaces().Delete(
namespaceName,
&metav1.DeleteOptions{},
)
if err != nil {
log.Warn(fmt.Errorf("Error deleting namespace '%s': %s", namespaceName, err))
return err
} else {
log.Info(fmt.Sprintf("Deleted namespace '%s'", namespaceName))
return nil
}
}
Loading

0 comments on commit 1eff034

Please sign in to comment.