mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor files
This commit is contained in:
32
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/codec/BUILD
generated
vendored
Normal file
32
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/codec/BUILD
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["codec.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/codec",
|
||||
deps = [
|
||||
"//pkg/api/legacyscheme:go_default_library",
|
||||
"//pkg/apis/core/install:go_default_library",
|
||||
"//pkg/kubelet/apis/kubeletconfig:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
65
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/codec/codec.go
generated
vendored
Normal file
65
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/codec/codec.go
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package codec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
// ensure the core apis are installed
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
|
||||
)
|
||||
|
||||
// TODO(mtaufen): allow an encoder to be injected into checkpoint objects at creation time? (then we could ultimately instantiate only one encoder)
|
||||
|
||||
// NewJSONEncoder generates a new runtime.Encoder that encodes objects to JSON
|
||||
func NewJSONEncoder(groupName string) (runtime.Encoder, error) {
|
||||
// encode to json
|
||||
mediaType := "application/json"
|
||||
info, ok := runtime.SerializerInfoForMediaType(legacyscheme.Codecs.SupportedMediaTypes(), mediaType)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported media type %q", mediaType)
|
||||
}
|
||||
|
||||
versions := legacyscheme.Registry.EnabledVersionsForGroup(groupName)
|
||||
if len(versions) == 0 {
|
||||
return nil, fmt.Errorf("no enabled versions for group %q", groupName)
|
||||
}
|
||||
|
||||
// the "best" version supposedly comes first in the list returned from legacyscheme.Registry.EnabledVersionsForGroup
|
||||
return legacyscheme.Codecs.EncoderForVersion(info.Serializer, versions[0]), nil
|
||||
}
|
||||
|
||||
// DecodeKubeletConfiguration decodes a serialized KubeletConfiguration to the internal type
|
||||
func DecodeKubeletConfiguration(kubeletCodecs *serializer.CodecFactory, data []byte) (*kubeletconfig.KubeletConfiguration, error) {
|
||||
// the UniversalDecoder runs defaulting and returns the internal type by default
|
||||
obj, gvk, err := kubeletCodecs.UniversalDecoder().Decode(data, nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode, error: %v", err)
|
||||
}
|
||||
|
||||
internalKC, ok := obj.(*kubeletconfig.KubeletConfiguration)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("failed to cast object to KubeletConfiguration, unexpected type: %v", gvk)
|
||||
}
|
||||
|
||||
return internalKC, nil
|
||||
}
|
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/equal/BUILD
generated
vendored
Normal file
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/equal/BUILD
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["equal.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/equal",
|
||||
deps = ["//vendor/k8s.io/api/core/v1:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
51
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/equal/equal.go
generated
vendored
Normal file
51
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/equal/equal.go
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package equal
|
||||
|
||||
import apiv1 "k8s.io/api/core/v1"
|
||||
|
||||
// ConfigSourceEq returns true if the two config sources are semantically equivalent in the context of dynamic config
|
||||
func ConfigSourceEq(a, b *apiv1.NodeConfigSource) bool {
|
||||
if a == b {
|
||||
return true
|
||||
} else if a == nil || b == nil {
|
||||
// not equal, and one is nil
|
||||
return false
|
||||
}
|
||||
// check equality of config source subifelds
|
||||
if a.ConfigMapRef != b.ConfigMapRef {
|
||||
return ObjectRefEq(a.ConfigMapRef, b.ConfigMapRef)
|
||||
}
|
||||
// all internal subfields of the config soruce are equal
|
||||
return true
|
||||
}
|
||||
|
||||
// ObjectRefEq returns true if the two object references are semantically equivalent in the context of dynamic config
|
||||
func ObjectRefEq(a, b *apiv1.ObjectReference) bool {
|
||||
if a == b {
|
||||
return true
|
||||
} else if a == nil || b == nil {
|
||||
// not equal, and one is nil
|
||||
return false
|
||||
}
|
||||
return a.UID == b.UID && a.Namespace == b.Namespace && a.Name == b.Name
|
||||
}
|
||||
|
||||
// ConfigOKEq returns true if the two conditions are semantically equivalent in the context of dynamic config
|
||||
func ConfigOKEq(a, b *apiv1.NodeCondition) bool {
|
||||
return a.Message == b.Message && a.Reason == b.Reason && a.Status == b.Status
|
||||
}
|
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/files/BUILD
generated
vendored
Normal file
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/files/BUILD
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["files.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/files",
|
||||
deps = ["//pkg/util/filesystem:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
139
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/files/files.go
generated
vendored
Normal file
139
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/files/files.go
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package files
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
utilfs "k8s.io/kubernetes/pkg/util/filesystem"
|
||||
)
|
||||
|
||||
const defaultPerm = 0666
|
||||
|
||||
// FileExists returns true if a regular file exists at `path`, false if `path` does not exist, otherwise an error
|
||||
func FileExists(fs utilfs.Filesystem, path string) (bool, error) {
|
||||
if info, err := fs.Stat(path); err == nil {
|
||||
if info.Mode().IsRegular() {
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("expected regular file at %q, but mode is %q", path, info.Mode().String())
|
||||
} else if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
} else {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureFile ensures that a regular file exists at `path`, and if it must create the file any
|
||||
// necessary parent directories will also be created and the new file will be empty.
|
||||
func EnsureFile(fs utilfs.Filesystem, path string) error {
|
||||
// if file exists, don't change it, but do report any unexpected errors
|
||||
if ok, err := FileExists(fs, path); ok || err != nil {
|
||||
return err
|
||||
} // Assert: file does not exist
|
||||
|
||||
// create any necessary parents
|
||||
err := fs.MkdirAll(filepath.Dir(path), defaultPerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create the file
|
||||
file, err := fs.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// close the file, since we don't intend to use it yet
|
||||
return file.Close()
|
||||
}
|
||||
|
||||
// WriteTmpFile creates a temporary file at `path`, writes `data` into it, and fsyncs the file
|
||||
func WriteTmpFile(fs utilfs.Filesystem, path string, data []byte) (tmpPath string, retErr error) {
|
||||
dir := filepath.Dir(path)
|
||||
prefix := filepath.Base(path)
|
||||
|
||||
// create the tmp file
|
||||
tmpFile, err := fs.TempFile(dir, prefix)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer func() {
|
||||
// close the file, return the close error only if there haven't been any other errors
|
||||
if err := tmpFile.Close(); retErr == nil {
|
||||
retErr = err
|
||||
}
|
||||
// if there was an error writing, syncing, or closing, delete the temporary file and return the error
|
||||
if retErr != nil {
|
||||
if err := fs.Remove(tmpPath); err != nil {
|
||||
retErr = fmt.Errorf("attempted to remove temporary file %q after error %v, but failed due to error: %v", path, retErr, err)
|
||||
}
|
||||
tmpPath = ""
|
||||
}
|
||||
}()
|
||||
|
||||
// Name() will be an absolute path when using utilfs.DefaultFS, because ioutil.TempFile passes
|
||||
// an absolute path to os.Open, and we ensure similar behavior in utilfs.FakeFS for testing.
|
||||
tmpPath = tmpFile.Name()
|
||||
|
||||
// write data
|
||||
if _, err := tmpFile.Write(data); err != nil {
|
||||
return tmpPath, err
|
||||
}
|
||||
// sync file, to ensure it's written in case a hard reset happens
|
||||
return tmpPath, tmpFile.Sync()
|
||||
}
|
||||
|
||||
// ReplaceFile replaces the contents of the file at `path` with `data` by writing to a tmp file in the same
|
||||
// dir as `path` and renaming the tmp file over `path`. The file does not have to exist to use ReplaceFile.
|
||||
// Note ReplaceFile calls fsync.
|
||||
func ReplaceFile(fs utilfs.Filesystem, path string, data []byte) error {
|
||||
// write data to a temporary file
|
||||
tmpPath, err := WriteTmpFile(fs, path, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// rename over existing file
|
||||
return fs.Rename(tmpPath, path)
|
||||
}
|
||||
|
||||
// DirExists returns true if a directory exists at `path`, false if `path` does not exist, otherwise an error
|
||||
func DirExists(fs utilfs.Filesystem, path string) (bool, error) {
|
||||
if info, err := fs.Stat(path); err == nil {
|
||||
if info.IsDir() {
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("expected dir at %q, but mode is is %q", path, info.Mode().String())
|
||||
} else if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
} else {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureDir ensures that a directory exists at `path`, and if it must create the directory any
|
||||
// necessary parent directories will also be created and the new directory will be empty.
|
||||
func EnsureDir(fs utilfs.Filesystem, path string) error {
|
||||
// if dir exists, don't change it, but do report any unexpected errors
|
||||
if ok, err := DirExists(fs, path); ok || err != nil {
|
||||
return err
|
||||
} // Assert: dir does not exist
|
||||
|
||||
// create the dir
|
||||
return fs.MkdirAll(path, defaultPerm)
|
||||
}
|
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/log/BUILD
generated
vendored
Normal file
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/log/BUILD
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["log.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/log",
|
||||
deps = ["//vendor/github.com/golang/glog:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
49
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/log/log.go
generated
vendored
Normal file
49
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/log/log.go
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
const logFmt = "kubelet config controller: %s"
|
||||
|
||||
// Errorf shim that inserts "kubelet config controller" at the beginning of the log message,
|
||||
// while still reporting the call site of the logging function.
|
||||
func Errorf(format string, args ...interface{}) {
|
||||
var s string
|
||||
if len(args) > 0 {
|
||||
s = fmt.Sprintf(format, args...)
|
||||
} else {
|
||||
s = format
|
||||
}
|
||||
glog.ErrorDepth(1, fmt.Sprintf(logFmt, s))
|
||||
}
|
||||
|
||||
// Infof shim that inserts "kubelet config controller" at the beginning of the log message,
|
||||
// while still reporting the call site of the logging function.
|
||||
func Infof(format string, args ...interface{}) {
|
||||
var s string
|
||||
if len(args) > 0 {
|
||||
s = fmt.Sprintf(format, args...)
|
||||
} else {
|
||||
s = format
|
||||
}
|
||||
glog.InfoDepth(1, fmt.Sprintf(logFmt, s))
|
||||
}
|
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/panic/BUILD
generated
vendored
Normal file
26
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/panic/BUILD
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["panic.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/panic",
|
||||
deps = ["//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
36
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/panic/panic.go
generated
vendored
Normal file
36
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/panic/panic.go
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package panic
|
||||
|
||||
import utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
|
||||
// HandlePanic returns a function that wraps `fn` with the utilruntime.PanicHandlers, and continues
|
||||
// to bubble the panic after the PanicHandlers are called
|
||||
func HandlePanic(fn func()) func() {
|
||||
return func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
for _, fn := range utilruntime.PanicHandlers {
|
||||
fn(r)
|
||||
}
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
// call the function
|
||||
fn()
|
||||
}
|
||||
}
|
25
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/test/BUILD
generated
vendored
Normal file
25
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/test/BUILD
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["test.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/test",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
40
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/test/test.go
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/test/test.go
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// SkipRest returns true if there was a non-nil error or if we expected an error that didn't happen,
|
||||
// and logs the appropriate error on the test object.
|
||||
// The return value indicates whether we should skip the rest of the test case due to the error result.
|
||||
func SkipRest(t *testing.T, desc string, err error, contains string) bool {
|
||||
if err != nil {
|
||||
if len(contains) == 0 {
|
||||
t.Errorf("case %q, expect nil error but got %q", desc, err.Error())
|
||||
} else if !strings.Contains(err.Error(), contains) {
|
||||
t.Errorf("case %q, expect error to contain %q but got %q", desc, contains, err.Error())
|
||||
}
|
||||
return true
|
||||
} else if len(contains) > 0 {
|
||||
t.Errorf("case %q, expect error to contain %q but got nil error", desc, contains)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user