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

Commit

Permalink
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: `make test-e2e-os` which runs \
`go test -run os`
  • Loading branch information
ashetty1 committed Dec 13, 2017
1 parent f36f473 commit 18f2430
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 194 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ endif
endif
endif

.PHONY: test-e2e-os
test-e2e-os:
go test -v -run os github.com/kedgeproject/kedge/tests/e2e

# Run all tests
.PHONY: test
test: test-dep validate test-unit test-unit-cover
Expand Down Expand Up @@ -127,4 +131,3 @@ vendor-update:
.PHONY: test-jsonschema-generation
test-jsonschema-generation:
docker run -v `pwd`/pkg/spec/types.go:/data/types.go:ro,Z surajd/kedgeschema

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
195 changes: 3 additions & 192 deletions tests/e2e/e2e_test.go → tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var BinaryLocation = ProjectPath + "kedge"
var BinaryCommand = []string{"create", "-n"}

const (
jobTimeout = 10 * time.Minute
jobTimeout = 10 * time.Minute
waitInterval = 5
)

func homeDir() string {
Expand Down Expand Up @@ -146,8 +147,7 @@ func PodsStarted(t *testing.T, clientset *kubernetes.Clientset, namespace string

// Wait for the jobs to complete
func waitForJobComplete(clientset *kubernetes.Clientset, namespace string, jobName string) error {
// Interval of 5
return wait.Poll(5, jobTimeout, func() (bool, error) {
return wait.Poll(waitInterval, jobTimeout, func() (bool, error) {
jobStatus, err := clientset.Batch().Jobs(namespace).Get(jobName, metav1.GetOptions{})
if err != nil {
return false, errors.Wrap(err, "error getting jobs")
Expand Down 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!")
}
})
}
}
Loading

0 comments on commit 18f2430

Please sign in to comment.