Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions tests/e2e/lib/apps.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package lib

import (
"bytes"
"context"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"

"github.com/onsi/ginkgo/v2"
ocpappsv1 "github.com/openshift/api/apps/v1"
routev1 "github.com/openshift/api/route/v1"
security "github.com/openshift/api/security/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -18,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func InstallApplication(ocClient client.Client, file string) error {
Expand Down Expand Up @@ -197,3 +203,54 @@ func RunMustGather(oc_cli string, artifact_dir string) error {
_, err := cmd.Output()
return err
}

func VerifyBackUpRestoreData(artifact_dir string, namespace string, routeName string, app string) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func VerifyBackUpRestoreData(artifact_dir string, namespace string, routeName string, app string) error {
func VerifyBackupRestoreData(artifact_dir string, namespace string, routeName string, app string) error {

log.Printf("Verifying backup/restore data of %s", app)
appRoute := &routev1.Route{}
clientv1, err := client.New(config.GetConfigOrDie(), client.Options{})
if err != nil {
return err
}
backupFile := artifact_dir + "/backup-data.txt"
routev1.AddToScheme(clientv1.Scheme())
err = clientv1.Get(context.Background(), client.ObjectKey{
Namespace: namespace,
Name: routeName,
}, appRoute)
if err != nil {
return err
}
appApi := "http://" + appRoute.Spec.Host
switch app {
case "todolist":
appApi += "/todo-completed"
case "parks-app":
appApi += "/parks"
}
resp, err := http.Get(appApi)
if err != nil {
return err
}
defer resp.Body.Close()

respData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if _, err := os.Stat(backupFile); err == nil {
backupData, err := os.ReadFile(backupFile)
if err != nil {
return err
}
os.Remove(backupFile)
if bytes.Compare(backupData, respData) != 0 {
return errors.New("Backup and Restore Data are not the same")
}
} else if errors.Is(err, os.ErrNotExist) {
err := os.WriteFile(backupFile, respData, 0644)
if err != nil {
return err
}
}
return nil
}