k8s.io/kubernetes@v1.29.3/test/e2e_node/remote/types.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Package remote contains implementations of the TestSuite interface, which specify
    18  // how to run various node test suites remotely.
    19  package remote
    20  
    21  import (
    22  	"fmt"
    23  	"time"
    24  )
    25  
    26  // TestSuite is the interface of a test suite, such as node e2e, node conformance,
    27  // node soaking, cri validation etc.
    28  type TestSuite interface {
    29  	// SetupTestPackage setup the test package in the given directory. TestSuite
    30  	// should put all necessary binaries and dependencies into the path. The caller
    31  	// will:
    32  	// * create a tarball with the directory.
    33  	// * deploy the tarball to the testing host.
    34  	// * untar the tarball to the testing workspace on the testing host.
    35  	SetupTestPackage(path, systemSpecName string) error
    36  	// RunTest runs test on the node in the given workspace and returns test output
    37  	// and test error if there is any.
    38  	// * host is the target node to run the test.
    39  	// * workspace is the directory on the testing host the test is running in. Note
    40  	//   that the test package is unpacked in the workspace before running the test.
    41  	// * results is the directory the test should write result into. All logs should be
    42  	//   saved as *.log, all junit file should start with junit*.
    43  	// * imageDesc is the description of the image the test is running on.
    44  	//   It will be used for logging purpose only.
    45  	// * junitFilePrefix is the prefix of output junit file.
    46  	// * testArgs is the arguments passed to test.
    47  	// * ginkgoArgs is the arguments passed to ginkgo.
    48  	// * systemSpecName is the name of the system spec used for validating the
    49  	//   image on which the test runs.
    50  	// * extraEnvs is the extra environment variables needed for node e2e tests.
    51  	// * runtimeConfig is the API runtime configuration used for node e2e tests.
    52  	// * timeout is the test timeout.
    53  	RunTest(host, workspace, results, imageDesc, junitFilePrefix, testArgs, ginkgoArgs, systemSpecName, extraEnvs, runtimeConfig string, timeout time.Duration) (string, error)
    54  }
    55  
    56  var testSuites = make(map[string]TestSuite)
    57  
    58  func RegisterTestSuite(name string, suite TestSuite) {
    59  	testSuites[name] = suite
    60  }
    61  
    62  func GetTestSuiteKeys() []string {
    63  	var keys []string
    64  	for key := range testSuites {
    65  		keys = append(keys, key)
    66  	}
    67  	return keys
    68  }
    69  
    70  func GetTestSuite(name string) (TestSuite, error) {
    71  	suite, ok := testSuites[name]
    72  	if ok {
    73  		return suite, nil
    74  	}
    75  	return nil, fmt.Errorf("unable to find testsuite for %s", name)
    76  }
    77  
    78  type NewRunner func(Config) Runner
    79  
    80  var runners = make(map[string]NewRunner)
    81  
    82  func RegisterRunner(name string, runner NewRunner) {
    83  	runners[name] = runner
    84  }
    85  
    86  func GetRunner(name string) (NewRunner, error) {
    87  	runner, ok := runners[name]
    88  	if ok {
    89  		return runner, nil
    90  	}
    91  	return nil, fmt.Errorf("unable to runner for %s", name)
    92  }