mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #108190 from stevekuznetsov/skuznets/storage-clearer-rv
storage: etcd: TestList: improve RV choices
This commit is contained in:
		@@ -1164,6 +1164,13 @@ func TestList(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// we want to figure out the resourceVersion before we create anything
 | 
				
			||||||
 | 
						initialList := &example.PodList{}
 | 
				
			||||||
 | 
						if err := store.List(ctx, "/", storage.ListOptions{Predicate: storage.Everything}, initialList); err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected List error: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						initialRV := initialList.ResourceVersion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i, ps := range preset {
 | 
						for i, ps := range preset {
 | 
				
			||||||
		preset[i].storedObj = &example.Pod{}
 | 
							preset[i].storedObj = &example.Pod{}
 | 
				
			||||||
		err := store.Create(ctx, ps.key, ps.obj, preset[i].storedObj, 0)
 | 
							err := store.Create(ctx, ps.key, ps.obj, preset[i].storedObj, 0)
 | 
				
			||||||
@@ -1244,16 +1251,16 @@ func TestList(t *testing.T) {
 | 
				
			|||||||
			rv:          "0",
 | 
								rv:          "0",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:        "test List on existing key with resource version set to 1, match=Exact",
 | 
								name:        "test List on existing key with resource version set before first write, match=Exact",
 | 
				
			||||||
			prefix:      "/one-level/",
 | 
								prefix:      "/one-level/",
 | 
				
			||||||
			pred:        storage.Everything,
 | 
								pred:        storage.Everything,
 | 
				
			||||||
			expectedOut: []*example.Pod{},
 | 
								expectedOut: []*example.Pod{},
 | 
				
			||||||
			rv:          "1",
 | 
								rv:          initialRV,
 | 
				
			||||||
			rvMatch:     metav1.ResourceVersionMatchExact,
 | 
								rvMatch:     metav1.ResourceVersionMatchExact,
 | 
				
			||||||
			expectRV:    "1",
 | 
								expectRV:    initialRV,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:        "test List on existing key with resource version set to 1, match=NotOlderThan",
 | 
								name:        "test List on existing key with resource version set to 0, match=NotOlderThan",
 | 
				
			||||||
			prefix:      "/one-level/",
 | 
								prefix:      "/one-level/",
 | 
				
			||||||
			pred:        storage.Everything,
 | 
								pred:        storage.Everything,
 | 
				
			||||||
			expectedOut: []*example.Pod{preset[0].storedObj},
 | 
								expectedOut: []*example.Pod{preset[0].storedObj},
 | 
				
			||||||
@@ -1261,13 +1268,29 @@ func TestList(t *testing.T) {
 | 
				
			|||||||
			rvMatch:     metav1.ResourceVersionMatchNotOlderThan,
 | 
								rvMatch:     metav1.ResourceVersionMatchNotOlderThan,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:        "test List on existing key with resource version set to 1, match=Invalid",
 | 
								name:        "test List on existing key with resource version set to 0, match=Invalid",
 | 
				
			||||||
			prefix:      "/one-level/",
 | 
								prefix:      "/one-level/",
 | 
				
			||||||
			pred:        storage.Everything,
 | 
								pred:        storage.Everything,
 | 
				
			||||||
			rv:          "0",
 | 
								rv:          "0",
 | 
				
			||||||
			rvMatch:     "Invalid",
 | 
								rvMatch:     "Invalid",
 | 
				
			||||||
			expectError: true,
 | 
								expectError: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name:        "test List on existing key with resource version set before first write, match=NotOlderThan",
 | 
				
			||||||
 | 
								prefix:      "/one-level/",
 | 
				
			||||||
 | 
								pred:        storage.Everything,
 | 
				
			||||||
 | 
								expectedOut: []*example.Pod{preset[0].storedObj},
 | 
				
			||||||
 | 
								rv:          initialRV,
 | 
				
			||||||
 | 
								rvMatch:     metav1.ResourceVersionMatchNotOlderThan,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name:        "test List on existing key with resource version set before first write, match=Invalid",
 | 
				
			||||||
 | 
								prefix:      "/one-level/",
 | 
				
			||||||
 | 
								pred:        storage.Everything,
 | 
				
			||||||
 | 
								rv:          initialRV,
 | 
				
			||||||
 | 
								rvMatch:     "Invalid",
 | 
				
			||||||
 | 
								expectError: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:        "test List on existing key with resource version set to current resource version",
 | 
								name:        "test List on existing key with resource version set to current resource version",
 | 
				
			||||||
			prefix:      "/one-level/",
 | 
								prefix:      "/one-level/",
 | 
				
			||||||
@@ -1378,7 +1401,7 @@ func TestList(t *testing.T) {
 | 
				
			|||||||
			expectRV:                   list.ResourceVersion,
 | 
								expectRV:                   list.ResourceVersion,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:   "test List with limit at resource version 1 and match=Exact",
 | 
								name:   "test List with limit at resource version before first write and match=Exact",
 | 
				
			||||||
			prefix: "/two-level/",
 | 
								prefix: "/two-level/",
 | 
				
			||||||
			pred: storage.SelectionPredicate{
 | 
								pred: storage.SelectionPredicate{
 | 
				
			||||||
				Label: labels.Everything(),
 | 
									Label: labels.Everything(),
 | 
				
			||||||
@@ -1387,9 +1410,9 @@ func TestList(t *testing.T) {
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
			expectedOut:    []*example.Pod{},
 | 
								expectedOut:    []*example.Pod{},
 | 
				
			||||||
			expectContinue: false,
 | 
								expectContinue: false,
 | 
				
			||||||
			rv:             "1",
 | 
								rv:             initialRV,
 | 
				
			||||||
			rvMatch:        metav1.ResourceVersionMatchExact,
 | 
								rvMatch:        metav1.ResourceVersionMatchExact,
 | 
				
			||||||
			expectRV:       "1",
 | 
								expectRV:       initialRV,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:          "test List with limit when paging disabled",
 | 
								name:          "test List with limit when paging disabled",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user