github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/test/validation/test_suite_test.go (about)

     1  package conformance
     2  
     3  import (
     4  	"flag"
     5  	"log"
     6  	"path"
     7  	"testing"
     8  	"time"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  
    13  	kniK8sReporter "github.com/openshift-kni/k8sreporter"
    14  
    15  	// Test files in this package must not end with `_test.go` suffix, as they are imported as go package
    16  	_ "github.com/k8snetworkplumbingwg/sriov-network-operator/test/validation/tests"
    17  
    18  	"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/k8sreporter"
    19  )
    20  
    21  var (
    22  	customReporter *kniK8sReporter.KubernetesReporter
    23  	err            error
    24  	reportPath     *string
    25  )
    26  
    27  func init() {
    28  	reportPath = flag.String("report", "", "the path of the report directory containing details for failed tests")
    29  }
    30  
    31  func TestTest(t *testing.T) {
    32  	// We want to collect logs before any resource is deleted in AfterEach, so we register the global fail handler
    33  	// in a way such that the reporter's Dump is always called before the default Fail.
    34  	RegisterFailHandler(
    35  		func(message string, callerSkip ...int) {
    36  			if customReporter != nil {
    37  				customReporter.Dump(10*time.Minute, CurrentSpecReport().FullText())
    38  			}
    39  
    40  			// Ensure failing line location is not affected by this wrapper
    41  			for i := range callerSkip {
    42  				callerSkip[i]++
    43  			}
    44  			Fail(message, callerSkip...)
    45  		})
    46  
    47  	if *reportPath != "" {
    48  		reportFile := path.Join(*reportPath, "sriov_failure_report.log")
    49  		customReporter, err = k8sreporter.New(reportFile)
    50  		if err != nil {
    51  			log.Fatalf("Failed to create the k8s reporter %s", err)
    52  		}
    53  	}
    54  
    55  	RunSpecs(t, "SRIOV Operator validation tests")
    56  }