Skip to content
This repository was archived by the owner on Nov 18, 2020. It is now read-only.

*: forgot to add some new files... #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions memcached-operator/build/test-framework/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG BASEIMAGE
FROM ${BASEIMAGE}
ADD build/_output/bin/memcached-operator-test /usr/local/bin/memcached-operator-test
ARG NAMESPACEDMAN
ADD $NAMESPACEDMAN /namespaced.yaml
ADD build/test-framework/go-test.sh /go-test.sh
3 changes: 3 additions & 0 deletions memcached-operator/build/test-framework/go-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

memcached-operator-test -test.parallel=1 -test.failfast -root=/ -kubeconfig=incluster -namespacedMan=namespaced.yaml -test.v
4 changes: 4 additions & 0 deletions memcached-operator/deploy/service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: memcached-operator
16 changes: 16 additions & 0 deletions memcached-operator/deploy/test-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Pod
metadata:
name: memcached-operator-test
spec:
restartPolicy: Never
containers:
- name: memcached-operator-test
image: quay.io/example/memcached-operator:v0.0.1
imagePullPolicy: Always
command: ["/go-test.sh"]
env:
- name: TEST_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
25 changes: 25 additions & 0 deletions memcached-operator/test/e2e/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018 The Operator-SDK Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"testing"

f "github.com/operator-framework/operator-sdk/pkg/test"
)

func TestMain(m *testing.M) {
f.MainEntry(m)
}
125 changes: 125 additions & 0 deletions memcached-operator/test/e2e/memcached_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright 2018 The Operator-SDK Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
goctx "context"
"fmt"
"testing"
"time"

apis "github.com/operator-framework/operator-sdk-samples/memcached-operator/pkg/apis"
operator "github.com/operator-framework/operator-sdk-samples/memcached-operator/pkg/apis/cache/v1alpha1"

framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

var (
retryInterval = time.Second * 5
timeout = time.Second * 60
cleanupRetryInterval = time.Second * 1
cleanupTimeout = time.Second * 5
)

func TestMemcached(t *testing.T) {
memcachedList := &operator.MemcachedList{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
}
err := framework.AddToFrameworkScheme(apis.AddToScheme, memcachedList)
if err != nil {
t.Fatalf("failed to add custom resource scheme to framework: %v", err)
}
// run subtests
t.Run("memcached-group", func(t *testing.T) {
t.Run("Cluster", MemcachedCluster)
t.Run("Cluster2", MemcachedCluster)
})
}

func memcachedScaleTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) error {
namespace, err := ctx.GetNamespace()
if err != nil {
return fmt.Errorf("could not get namespace: %v", err)
}
// create memcached custom resource
exampleMemcached := &operator.Memcached{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "example-memcached",
Namespace: namespace,
},
Spec: operator.MemcachedSpec{
Size: 3,
},
}
// use TestCtx's create helper to create the object and add a cleanup function for the new object
err = f.Client.Create(goctx.TODO(), exampleMemcached, &framework.CleanupOptions{TestContext: ctx, Timeout: cleanupTimeout, RetryInterval: cleanupRetryInterval})
if err != nil {
return err
}
// wait for example-memcached to reach 3 replicas
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "example-memcached", 3, retryInterval, timeout)
if err != nil {
return err
}

err = f.Client.Get(goctx.TODO(), types.NamespacedName{Name: "example-memcached", Namespace: namespace}, exampleMemcached)
if err != nil {
return err
}
exampleMemcached.Spec.Size = 4
err = f.Client.Update(goctx.TODO(), exampleMemcached)
if err != nil {
return err
}

// wait for example-memcached to reach 4 replicas
return e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "example-memcached", 4, retryInterval, timeout)
}

func MemcachedCluster(t *testing.T) {
t.Parallel()
ctx := framework.NewTestCtx(t)
defer ctx.Cleanup()
err := ctx.InitializeClusterResources(&framework.CleanupOptions{TestContext: ctx, Timeout: cleanupTimeout, RetryInterval: cleanupRetryInterval})
if err != nil {
t.Fatalf("failed to initialize cluster resources: %v", err)
}
t.Log("Initialized cluster resources")
namespace, err := ctx.GetNamespace()
if err != nil {
t.Fatal(err)
}
// get global framework variables
f := framework.Global
// wait for memcached-operator to be ready
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "memcached-operator", 1, retryInterval, timeout)
if err != nil {
t.Fatal(err)
}

if err = memcachedScaleTest(t, f, ctx); err != nil {
t.Fatal(err)
}
}
Loading