Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
[WIP] Adding OpenShift tests
Browse files Browse the repository at this point in the history
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
ashetty1 committed Dec 6, 2017
1 parent 203b237 commit 9237042
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 190 deletions.
2 changes: 1 addition & 1 deletion scripts/run_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

run_command="go test"
run_command="go test -run k8s"

while getopts ":p:t:" opt; do
case $opt in
Expand Down
189 changes: 0 additions & 189 deletions tests/e2e/e2e_test.go → tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,192 +255,3 @@ type testData struct {
NodePortServices []ServicePort
Type string
}

// 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_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!")
}
})
}
}
195 changes: 195 additions & 0 deletions tests/e2e/e2e_k8s_test.go
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!")
}
})
}
}
Loading

0 comments on commit 9237042

Please sign in to comment.