Files
.github
api
cmd
docs
examples
install
internal
api
app
appmain
config
filter
ipb
logging
rpc
statestore
telemetry
testing
e2e
README.md
backfill_test.go
cluster.go
cluster_test.go
common.go
fetch_matches_test.go
in_memory.go
query_backfills_test.go
query_tickets_test.go
ticket_test.go
mmf
fake_frontend.go
util
pkg
third_party
tools
tutorials
.dockerignore
.gcloudignore
.gitignore
.golangci.yaml
CONTRIBUTING.md
Dockerfile.base-build
Dockerfile.ci
Dockerfile.cmd
LICENSE
Makefile
README.md
cloudbuild.yaml
code-of-conduct.md
doc.go
go.mod
go.sum
open-match/internal/testing/e2e/cluster_test.go
2021-01-07 13:29:27 -08:00

107 lines
2.8 KiB
Go

// +build e2ecluster
// Copyright 2019 Google LLC
//
// 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 (
"context"
"fmt"
"os"
"strings"
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"open-match.dev/open-match/internal/app/evaluator"
"open-match.dev/open-match/internal/appmain/apptest"
"open-match.dev/open-match/internal/config"
mmfService "open-match.dev/open-match/internal/testing/mmf"
"open-match.dev/open-match/pkg/pb"
)
func TestServiceHealth(t *testing.T) {
kubeconfig, err := rest.InClusterConfig()
if err != nil {
t.Fatal(err)
}
kubeClient, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
t.Fatalf("%s: creating Kubernetes client from config failed\nconfig= %+v", err, kubeconfig)
}
namespace := os.Getenv("NAMESPACE")
podList, err := kubeClient.CoreV1().Pods(namespace).List(metav1.ListOptions{})
if err != nil {
t.Fatal(err)
}
for _, pod := range podList.Items {
if app, ok := pod.ObjectMeta.Labels["app"]; ok && app == "open-match" && pod.Status.Phase != corev1.PodRunning {
t.Errorf("pod %+v is not running.", pod)
}
}
}
func TestMain(m *testing.M) {
clusterStarted = true
mmf := func(ctx context.Context, profile *pb.MatchProfile, out chan<- *pb.Match) error {
return clusterMMF(ctx, profile, out)
}
eval := func(ctx context.Context, in <-chan *pb.Match, out chan<- string) error {
return clusterEval(ctx, in, out)
}
cleanup, err := apptest.RunInCluster(mmfService.BindServiceFor(mmf), evaluator.BindServiceFor(eval))
if err != nil {
fmt.Println("Error starting mmf and evaluator:", err)
os.Exit(1)
}
exitCode := m.Run()
err = cleanup()
if err != nil {
fmt.Println("Error stopping mmf and evaluator:", err)
os.Exit(1)
}
os.Exit(exitCode)
}
// TestConfigMatch covers that the config file used for local in memory e2e
// tests matches the configs used for the in cluster tests, to avoid drift.
func TestConfigMatch(t *testing.T) {
cfg, err := config.Read()
if err != nil {
t.Fatal(err)
}
cfgMemory := viper.New()
cfgMemory.SetConfigType("yaml")
err = cfgMemory.ReadConfig(strings.NewReader(configFile))
if err != nil {
t.Fatal(err)
}
require.Equal(t, cfgMemory.AllSettings(), cfg.AllSettings())
}