This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For OpenShift, we reuse the functions which we use for \ k8s tests. So for this purpose, this commit puts those \ functions into a separate file: tests/e2e/e2e.go The k8s tests are put under: tests/e2e/e2e_k8s_test.go The OpenShift tests are in tests/e2e/e2e_os_test.go The e2e script has been modified to run only k8s tests \ by default (by using the `go test -run k8s`) To run OpenShift tests: `go test -run os`
- Loading branch information
Showing
4 changed files
with
335 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package e2e | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
) | ||
|
||
// The "bread and butter" of the test-suite. We will iterate through | ||
// each test that is required and make sure that not only are the pods started | ||
// but that each test is pingable / is accessable. | ||
func Test_k8s_Integration(t *testing.T) { | ||
clientset, err := createClient() | ||
if err != nil { | ||
t.Fatalf("error getting kube client: %v", err) | ||
} | ||
|
||
tests := []testData{ | ||
{ | ||
TestName: "Testing configMap", | ||
Namespace: "configmap", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/configmap/db.yaml", | ||
ProjectPath + "docs/examples/configmap/web.yaml", | ||
}, | ||
PodStarted: []string{"web"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 8080}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Testing customVol", | ||
Namespace: "customvol", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/customVol/db.yaml", | ||
ProjectPath + "docs/examples/customVol/web.yaml", | ||
}, | ||
PodStarted: []string{"web"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 8080}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Testing includeResources", | ||
Namespace: "include-resources", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/includeResources/app.yaml", | ||
}, | ||
PodStarted: []string{"web"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "web", Port: 80}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Testing health", | ||
Namespace: "health", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/health/db.yaml", | ||
ProjectPath + "docs/examples/health/web.yaml", | ||
}, | ||
PodStarted: []string{"web"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 8080}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Testing healthChecks", | ||
Namespace: "healthchecks", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/healthchecks/db.yaml", | ||
ProjectPath + "docs/examples/healthchecks/web.yaml", | ||
}, | ||
PodStarted: []string{"web"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 8080}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Testing secret", | ||
Namespace: "secrets", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/secrets/db.yaml", | ||
ProjectPath + "docs/examples/secrets/web.yaml", | ||
}, | ||
PodStarted: []string{"web"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 8080}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Testing single file", | ||
Namespace: "singlefile", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/single_file/wordpress.yml", | ||
}, | ||
PodStarted: []string{"wordpress"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 8080}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Normal Wordpress test", | ||
Namespace: "wordpress", | ||
InputFiles: []string{ | ||
ProjectPath + "examples/wordpress/wordpress.yaml", | ||
ProjectPath + "examples/wordpress/mariadb.yaml", | ||
}, | ||
PodStarted: []string{"wordpress"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 80}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Test portMappings", | ||
Namespace: "portmappings", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/portMappings/wordpress.yaml", | ||
ProjectPath + "docs/examples/portMappings/mariadb.yaml", | ||
}, | ||
PodStarted: []string{"wordpress"}, | ||
NodePortServices: []ServicePort{ | ||
{Name: "wordpress", Port: 80}, | ||
{Name: "mariadb", Port: 3306}, | ||
}, | ||
}, | ||
{ | ||
TestName: "Test jobs", | ||
Namespace: "jobs", | ||
InputFiles: []string{ | ||
ProjectPath + "docs/examples/jobs/job.yaml", | ||
}, | ||
PodStarted: []string{"pival"}, | ||
Type: "job", | ||
}, | ||
} | ||
|
||
_, err = clientset.CoreV1().Pods("").List(metav1.ListOptions{}) | ||
if err != nil { | ||
t.Fatalf("Kubernetes cluster is not running or not accessible: %v", err) | ||
} | ||
|
||
for _, test := range tests { | ||
test := test // capture range variable | ||
t.Run(test.TestName, func(t *testing.T) { | ||
t.Parallel() | ||
// create a namespace | ||
_, err := createNS(clientset, test.Namespace) | ||
if err != nil { | ||
t.Fatalf("error creating namespace: %v", err) | ||
} | ||
t.Logf("namespace %q created", test.Namespace) | ||
defer deleteNamespace(t, clientset, test.Namespace) | ||
|
||
// run kedge | ||
convertedOutput, err := RunBinary(test.InputFiles, test.Namespace) | ||
if err != nil { | ||
t.Fatalf("error running kedge: %v", err) | ||
} | ||
t.Log(string(convertedOutput)) | ||
|
||
// see if the pods are running | ||
if err := PodsStarted(t, clientset, test.Namespace, test.PodStarted); err != nil { | ||
t.Fatalf("error finding running pods: %v", err) | ||
} | ||
|
||
if test.Type == "job" { | ||
listJobs, err := clientset.Batch().Jobs(test.Namespace).List(metav1.ListOptions{}) | ||
if err != nil { | ||
t.Fatalf("error getting the job list: %v", err) | ||
} | ||
|
||
for _, job := range listJobs.Items { | ||
err := waitForJobComplete(clientset, test.Namespace, job.Name) | ||
if err != nil { | ||
t.Fatalf("Job failed: %v", err) | ||
} | ||
|
||
t.Logf("Successfully completed the job: %s", job.Name) | ||
} | ||
} else { | ||
|
||
// get endpoints for all services | ||
endPoints, err := getEndPoints(t, clientset, test.Namespace, test.NodePortServices) | ||
if err != nil { | ||
t.Fatalf("error getting nodes: %v", err) | ||
} | ||
|
||
if err := pingEndPoints(t, endPoints); err != nil { | ||
t.Fatalf("error pinging endpoint: %v", err) | ||
} | ||
|
||
t.Logf("Successfully pinged all endpoints!") | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.