Skip to content

Commit

Permalink
Make dir for all of the failed tests
Browse files Browse the repository at this point in the history
This commit makes the k8s reporter to create a dir named
"metallb_failure_report.log" to place all the failed tests in it.

We ignore the error of dir already exist to allow it to
use the same dir for the validation and funcaitonal test suites.

Signed-off-by: Lior Noy <[email protected]>
  • Loading branch information
liornoy committed Sep 12, 2023
1 parent fe1468f commit 9ecbdd2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/e2e/functional/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func TestE2E(t *testing.T) {

if *reportPath != "" {
kubeconfig := os.Getenv("KUBECONFIG")
r = k8sreporter.New(kubeconfig, *reportPath, OperatorNameSpace)
reportPath := path.Join(*reportPath, "metallb_failure_report.log")
r = k8sreporter.New(kubeconfig, reportPath, OperatorNameSpace)
}

RunSpecs(t, "Metallb Operator E2E Suite", reporterConfig)
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/k8sreporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
package k8sreporter

import (
"errors"
"log"
"os"

"github.com/openshift-kni/k8sreporter"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -41,6 +43,11 @@ func New(kubeconfig, path, namespace string) *k8sreporter.KubernetesReporter {
{Cr: &corev1.ServiceList{}},
}

err := os.Mkdir(path, 0755)
if err != nil && !errors.Is(err, os.ErrExist) {
log.Fatalf("Failed to create the reporter dir: %s", err)
}

reporter, err := k8sreporter.New(kubeconfig, addToScheme, dumpNamespace, path, crds...)
if err != nil {
log.Fatalf("Failed to initialize the reporter %s", err)
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func TestValidation(t *testing.T) {

if *reportPath != "" {
kubeconfig := os.Getenv("KUBECONFIG")
r = k8sreporter.New(kubeconfig, *reportPath, OperatorNameSpace)
reportPath := path.Join(*reportPath, "metallb_failure_report.log")
r = k8sreporter.New(kubeconfig, reportPath, OperatorNameSpace)
}

RunSpecs(t, "Metallb Operator Validation Suite", reporterConfig)
Expand Down

0 comments on commit 9ecbdd2

Please sign in to comment.