mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-31 22:59:34 +00:00
allocate a unique scheme for each test to fix concurrent usage issue
Kubernetes-commit: d66b3edd65efba0760eb0a5668aac733f294903b
This commit is contained in:
committed by
Kubernetes Publisher
parent
af150e1667
commit
470c93d04c
@@ -41,6 +41,11 @@ type MetadataClient interface {
|
||||
UpdateFake(obj *metav1.PartialObjectMetadata, opts metav1.UpdateOptions, subresources ...string) (*metav1.PartialObjectMetadata, error)
|
||||
}
|
||||
|
||||
// NewTestScheme creates a unique Scheme for each test.
|
||||
func NewTestScheme() *runtime.Scheme {
|
||||
return runtime.NewScheme()
|
||||
}
|
||||
|
||||
// NewSimpleMetadataClient creates a new client that will use the provided scheme and respond with the
|
||||
// provided objects when requests are made. It will track actions made to the client which can be checked
|
||||
// with GetActions().
|
||||
|
@@ -39,13 +39,6 @@ const (
|
||||
testAPIVersion = "testgroup/testversion"
|
||||
)
|
||||
|
||||
var scheme *runtime.Scheme
|
||||
|
||||
func init() {
|
||||
scheme = runtime.NewScheme()
|
||||
metav1.AddMetaToScheme(scheme)
|
||||
}
|
||||
|
||||
func newPartialObjectMetadata(apiVersion, kind, namespace, name string) *metav1.PartialObjectMetadata {
|
||||
return &metav1.PartialObjectMetadata{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
@@ -66,6 +59,8 @@ func newPartialObjectMetadataWithAnnotations(annotations map[string]string) *met
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
scheme := NewTestScheme()
|
||||
metav1.AddMetaToScheme(scheme)
|
||||
client := NewSimpleMetadataClient(scheme,
|
||||
newPartialObjectMetadata("group/version", "TheKind", "ns-foo", "name-foo"),
|
||||
newPartialObjectMetadata("group2/version", "TheKind", "ns-foo", "name2-foo"),
|
||||
@@ -98,6 +93,8 @@ type patchTestCase struct {
|
||||
}
|
||||
|
||||
func (tc *patchTestCase) runner(t *testing.T) {
|
||||
scheme := NewTestScheme()
|
||||
metav1.AddMetaToScheme(scheme)
|
||||
client := NewSimpleMetadataClient(scheme, tc.object)
|
||||
resourceInterface := client.Resource(schema.GroupVersionResource{Group: testGroup, Version: testVersion, Resource: testResource}).Namespace(testNamespace)
|
||||
|
||||
|
@@ -125,7 +125,7 @@ func TestMetadataSharedInformerFactory(t *testing.T) {
|
||||
timeout := time.Duration(3 * time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
scheme := runtime.NewScheme()
|
||||
scheme := fake.NewTestScheme()
|
||||
metav1.AddMetaToScheme(scheme)
|
||||
informerReciveObjectCh := make(chan *metav1.PartialObjectMetadata, 1)
|
||||
objs := []runtime.Object{}
|
||||
|
Reference in New Issue
Block a user