Skip to content

Commit

Permalink
Adding e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Simpson committed Mar 21, 2024
1 parent a52d4b8 commit ffb2aee
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ CMDS = $(shell find $(ROOT_DIR)/cmd -maxdepth 1 -mindepth 1 -type d | sed "s/^.*

.PHONY: test report mocks clean-mocks report-watch
test:
ginkgo --race -p --cover -covermode atomic -coverprofile=coverage.out --output-dir $(ROOT_DIR)/ $(ROOT_DIR)/...
ginkgo --race -p --cover -covermode atomic -coverprofile=coverage.out --output-dir $(ROOT_DIR)/ $(ROOT_DIR)/pkg/...

test-e2e:
@echo "Starting e2e integration tests"
ginkgo --race -p $(ROOT_DIR)/test/e2e/...

test-watch:
ginkgo watch --race -p --cover -covermode atomic -output-dir=$(ROOT_DIR) $(ROOT_DIR)/...
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/character_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package e2e_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Character e2e", func() {
It("should work", func() {
Expect(true).To(BeTrue())
})
})
12 changes: 12 additions & 0 deletions test/e2e/chat_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package e2e_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Chat e2e", func() {
It("should work", func() {
Expect(true).To(BeTrue())
})
})
102 changes: 102 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package e2e_test

import (
"bytes"
"context"
"encoding/gob"
"os"
"path/filepath"
"testing"

"github.com/bxcodec/faker/v4"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

var (
clientset *kubernetes.Clientset
testData *setupData
)

func TestE2e(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "E2E Suite")
}

type setupData struct {
// Namespace used for SRO
Namespace string

// Namespace used for Agones
AgonesNamespace string
}

var _ = SynchronizedBeforeSuite(func(ctx context.Context) []byte {
testData := setupData{
Namespace: "sro-testing-" + faker.Username(),
AgonesNamespace: "agones-system-testing-" + faker.Username(),
}
setupClientSet()

Expect(clientset.CoreV1().Namespaces().Create(
ctx,
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testData.Namespace,
},
},
metav1.CreateOptions{},
)).To(Succeed())
Expect(clientset.CoreV1().Namespaces().Create(
ctx,
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testData.AgonesNamespace,
},
},
metav1.CreateOptions{},
)).To(Succeed())

return testData.encode()
}, func(data []byte) {
testData = decodeSetupData(data)
setupClientSet()
})

var _ = SynchronizedAfterSuite(func() {}, func(ctx context.Context) {
Expect(clientset.CoreV1().Namespaces().Delete(ctx, testData.Namespace, metav1.DeleteOptions{})).
NotTo(HaveOccurred())
Expect(clientset.CoreV1().Namespaces().Delete(ctx, testData.AgonesNamespace, metav1.DeleteOptions{})).
NotTo(HaveOccurred())
})

func setupClientSet() {
homeDir, err := os.UserHomeDir()
Expect(err).NotTo(HaveOccurred(), "unable to get home directory")
Expect(homeDir).NotTo(BeEmpty())

config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(homeDir, ".kube", "config"))
Expect(err).NotTo(HaveOccurred(), "unable to get kubernetes config")

clientset, err = kubernetes.NewForConfig(config)
Expect(err).NotTo(HaveOccurred(), "kubernetes config invalid")
}

func (s *setupData) encode() []byte {
var buf *bytes.Buffer
enc := gob.NewEncoder(buf)
Expect(enc.Encode(s)).NotTo(HaveOccurred())
return buf.Bytes()
}

func decodeSetupData(in []byte) *setupData {
buf := bytes.NewBuffer(in)
out := &setupData{}
dec := gob.NewDecoder(buf)
Expect(dec.Decode(out)).NotTo(HaveOccurred())
return out
}
12 changes: 12 additions & 0 deletions test/e2e/gamebackend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package e2e_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Gamebackend e2e", func() {
It("should work", func() {
Expect(true).To(BeTrue())
})
})

0 comments on commit ffb2aee

Please sign in to comment.