Merge pull request #81393 from oomichi/cleanup-ReadOrDie

Remove fail argument from ReadOrDie()
This commit is contained in:
Kubernetes Prow Robot
2019-08-21 10:36:31 -07:00
committed by GitHub
11 changed files with 20 additions and 26 deletions

View File

@@ -12,7 +12,6 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//test/e2e/framework/testfiles:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
],
)

View File

@@ -23,8 +23,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/kubernetes/test/e2e/framework/testfiles"
"github.com/onsi/ginkgo"
)
const (
@@ -54,7 +52,7 @@ func NumberOfSampleResources(node *v1.Node) int64 {
// GetSampleDevicePluginPod returns the Device Plugin pod for sample resources in e2e tests
func GetSampleDevicePluginPod() *v1.Pod {
ds := ReadDaemonSetV1OrDie(testfiles.ReadOrDie(sampleDevicePluginDSYAML, ginkgo.Fail))
ds := ReadDaemonSetV1OrDie(testfiles.ReadOrDie(sampleDevicePluginDSYAML))
p := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: sampleDevicePluginName,

View File

@@ -399,10 +399,10 @@ func NewIngressTestJig(c clientset.Interface) *TestJig {
func (j *TestJig) CreateIngress(manifestPath, ns string, ingAnnotations map[string]string, svcAnnotations map[string]string) {
var err error
read := func(file string) string {
return string(testfiles.ReadOrDie(filepath.Join(manifestPath, file), ginkgo.Fail))
return string(testfiles.ReadOrDie(filepath.Join(manifestPath, file)))
}
exists := func(file string) bool {
return testfiles.Exists(filepath.Join(manifestPath, file), ginkgo.Fail)
return testfiles.Exists(filepath.Join(manifestPath, file))
}
j.Logger.Infof("creating replication controller")
@@ -844,7 +844,7 @@ type NginxIngressController struct {
// Init initializes the NginxIngressController
func (cont *NginxIngressController) Init() {
read := func(file string) string {
return string(testfiles.ReadOrDie(filepath.Join(IngressManifestPath, "nginx", file), ginkgo.Fail))
return string(testfiles.ReadOrDie(filepath.Join(IngressManifestPath, "nginx", file)))
}
e2elog.Logf("initializing nginx ingress controller")
framework.RunKubectlOrDieInput(read("rc.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", cont.Ns))

View File

@@ -5,6 +5,7 @@ go_library(
srcs = ["testfiles.go"],
importpath = "k8s.io/kubernetes/test/e2e/framework/testfiles",
visibility = ["//visibility:public"],
deps = ["//vendor/github.com/onsi/ginkgo:go_default_library"],
)
filegroup(

View File

@@ -33,6 +33,8 @@ import (
"path/filepath"
"sort"
"strings"
"github.com/onsi/ginkgo"
)
var filesources []FileSource
@@ -64,20 +66,14 @@ type FileSource interface {
DescribeFiles() string
}
// Fail is an error handler function with the same prototype and
// semantic as ginkgo.Fail. Typically ginkgo.Fail is what callers
// of ReadOrDie and Exists will pass. This way this package
// avoids depending on Ginkgo.
type Fail func(failure string, callerSkip ...int)
// ReadOrDie tries to retrieve the desired file content from
// one of the registered file sources. In contrast to FileSource, it
// will either return a valid slice or abort the test by calling the fatal function,
// i.e. the caller doesn't have to implement error checking.
func ReadOrDie(filePath string, fail Fail) []byte {
func ReadOrDie(filePath string) []byte {
data, err := Read(filePath)
if err != nil {
fail(err.Error(), 1)
ginkgo.Fail(err.Error(), 1)
}
return data
}
@@ -110,11 +106,11 @@ func Read(filePath string) ([]byte, error) {
// Exists checks whether a file could be read. Unexpected errors
// are handled by calling the fail function, which then should
// abort the current test.
func Exists(filePath string, fail Fail) bool {
func Exists(filePath string) bool {
for _, filesource := range filesources {
data, err := filesource.ReadTestFile(filePath)
if err != nil {
fail(fmt.Sprintf("fatal error looking for test file %s: %s", filePath, err), 1)
ginkgo.Fail(fmt.Sprintf("fatal error looking for test file %s: %s", filePath, err), 1)
}
if data != nil {
return true