mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
test/integration: use a known previous resourceVersion
ResourceVersion values are opaque and math should not be done on them. The intent of this test was to watch from a resourceVersion before the moment where the objects were created, and we can find such a version by listing from the API server before the tests begin. Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
This commit is contained in:
parent
85c43df3f6
commit
a843239ec3
@ -1417,6 +1417,12 @@ func TestTransform(t *testing.T) {
|
||||
crdGVR := schema.GroupVersionResource{Group: fooCRD.Spec.Group, Version: fooCRD.Spec.Versions[0].Name, Resource: "foos"}
|
||||
crclient := dynamicClient.Resource(crdGVR).Namespace(testNamespace)
|
||||
|
||||
previousList, err := crclient.List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to list CRs before test: %v", err)
|
||||
}
|
||||
previousRV := previousList.GetResourceVersion()
|
||||
|
||||
testcases := []struct {
|
||||
name string
|
||||
accept string
|
||||
@ -1957,16 +1963,20 @@ func TestTransform(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rv, _ := strconv.Atoi(obj.GetResourceVersion())
|
||||
if rv < 1 {
|
||||
rv = 1
|
||||
var rv string
|
||||
if obj.GetResourceVersion() == "" || obj.GetResourceVersion() == "0" {
|
||||
// no object was created in the preamble to the test, so get recent data
|
||||
rv = "0"
|
||||
} else {
|
||||
// we created an object, and need to list+watch from some time before the creation to see it
|
||||
rv = previousRV
|
||||
}
|
||||
|
||||
w, err := client.Get().
|
||||
Resource(resource).NamespaceIfScoped(obj.GetNamespace(), len(obj.GetNamespace()) > 0).
|
||||
SetHeader("Accept", tc.accept).
|
||||
VersionedParams(&metav1.ListOptions{
|
||||
ResourceVersion: strconv.Itoa(rv - 1),
|
||||
ResourceVersion: rv,
|
||||
Watch: true,
|
||||
FieldSelector: fields.OneTermEqualSelector("metadata.name", obj.GetName()).String(),
|
||||
}, metav1.ParameterCodec).
|
||||
|
Loading…
Reference in New Issue
Block a user