mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Only test requests that pass validation
This commit is contained in:
parent
75531ccc9c
commit
1b2bacda5b
@ -31,6 +31,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/internalversion/validation"
|
||||||
|
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
@ -205,64 +207,71 @@ func TestGetListCacheBypass(t *testing.T) {
|
|||||||
Continue string
|
Continue string
|
||||||
}
|
}
|
||||||
testCases := map[opts]bool{}
|
testCases := map[opts]bool{}
|
||||||
|
testCases[opts{}] = false
|
||||||
|
testCases[opts{Limit: 100}] = false
|
||||||
|
testCases[opts{Continue: "continue"}] = true
|
||||||
|
testCases[opts{Limit: 100, Continue: "continue"}] = true
|
||||||
|
testCases[opts{ResourceVersion: "0"}] = false
|
||||||
|
testCases[opts{ResourceVersion: "0", Limit: 100}] = false
|
||||||
|
testCases[opts{ResourceVersion: "0", Continue: "continue"}] = true
|
||||||
|
testCases[opts{ResourceVersion: "0", Limit: 100, Continue: "continue"}] = true
|
||||||
|
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan}] = false
|
||||||
|
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Limit: 100}] = false
|
||||||
|
testCases[opts{ResourceVersion: "1"}] = false
|
||||||
|
testCases[opts{ResourceVersion: "1", Limit: 100}] = true
|
||||||
|
testCases[opts{ResourceVersion: "1", Continue: "continue"}] = true
|
||||||
|
testCases[opts{ResourceVersion: "1", Limit: 100, Continue: "continue"}] = true
|
||||||
|
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchExact}] = true
|
||||||
|
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Limit: 100}] = true
|
||||||
|
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan}] = false
|
||||||
|
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Limit: 100}] = false
|
||||||
|
|
||||||
for _, rv := range []string{"", "0", "1"} {
|
for _, rv := range []string{"", "0", "1"} {
|
||||||
for _, match := range []metav1.ResourceVersionMatch{"", "Invalid", metav1.ResourceVersionMatchExact, metav1.ResourceVersionMatchNotOlderThan} {
|
for _, match := range []metav1.ResourceVersionMatch{"", metav1.ResourceVersionMatchExact, metav1.ResourceVersionMatchNotOlderThan} {
|
||||||
for _, c := range []string{"", "continue"} {
|
for _, c := range []string{"", "continue"} {
|
||||||
for _, limit := range []int64{0, 100} {
|
for _, limit := range []int64{0, 100} {
|
||||||
testCases[opts{
|
errs := validation.ValidateListOptions(&internalversion.ListOptions{
|
||||||
ResourceVersion: rv,
|
ResourceVersion: rv,
|
||||||
ResourceVersionMatch: match,
|
ResourceVersionMatch: match,
|
||||||
Continue: c,
|
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
}] = false
|
Continue: c,
|
||||||
|
}, false)
|
||||||
|
if len(errs) != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
opt := opts{
|
||||||
|
ResourceVersion: rv,
|
||||||
|
ResourceVersionMatch: match,
|
||||||
|
Limit: limit,
|
||||||
|
Continue: c,
|
||||||
|
}
|
||||||
|
_, found := testCases[opt]
|
||||||
|
if !found {
|
||||||
|
t.Errorf("Test case not covered, but passes validation: %+v", opt)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testCases[opts{ResourceVersion: "0", Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "0", Limit: 100, Continue: "continue"}] = true
|
for opt := range testCases {
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchExact}] = true
|
errs := validation.ValidateListOptions(&internalversion.ListOptions{
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Limit: 100}] = true
|
ResourceVersion: opt.ResourceVersion,
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Continue: "continue"}] = true
|
ResourceVersionMatch: opt.ResourceVersionMatch,
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Limit: 100, Continue: "continue"}] = true
|
Limit: opt.Limit,
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Continue: "continue"}] = true
|
Continue: opt.Continue,
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Limit: 100, Continue: "continue"}] = true
|
}, false)
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: "Invalid"}] = true
|
if len(errs) != 0 {
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: "Invalid", Continue: "continue"}] = true
|
t.Errorf("Invalid LIST request that should not be tested %+v", opt)
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: "Invalid", Limit: 100}] = true
|
continue
|
||||||
testCases[opts{ResourceVersion: "0", ResourceVersionMatch: "Invalid", Limit: 100, Continue: "continue"}] = true
|
}
|
||||||
testCases[opts{ResourceVersion: "1", Limit: 100}] = true
|
}
|
||||||
testCases[opts{ResourceVersion: "1", Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchExact}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Limit: 100}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: "Invalid"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: "Invalid", Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: "Invalid", Limit: 100}] = true
|
|
||||||
testCases[opts{ResourceVersion: "1", ResourceVersionMatch: "Invalid", Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Limit: 100}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchExact}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchExact, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchExact, Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: "Invalid"}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: "Invalid", Continue: "continue"}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: "Invalid", Limit: 100}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: "Invalid", Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{Limit: 100, Continue: "continue"}] = true
|
|
||||||
testCases[opts{Continue: "continue"}] = true
|
|
||||||
|
|
||||||
t.Run("ConsistentListFromStorage", func(t *testing.T) {
|
t.Run("ConsistentListFromStorage", func(t *testing.T) {
|
||||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, false)
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, false)
|
||||||
testCases[opts{}] = true
|
testCases[opts{}] = true
|
||||||
testCases[opts{Limit: 100}] = true
|
testCases[opts{Limit: 100}] = true
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan}] = true
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchExact, Limit: 100}] = true
|
|
||||||
for opt, expectBypass := range testCases {
|
for opt, expectBypass := range testCases {
|
||||||
testGetListCacheBypass(t, storage.ListOptions{
|
testGetListCacheBypass(t, storage.ListOptions{
|
||||||
ResourceVersion: opt.ResourceVersion,
|
ResourceVersion: opt.ResourceVersion,
|
||||||
@ -288,8 +297,6 @@ func TestGetListCacheBypass(t *testing.T) {
|
|||||||
|
|
||||||
testCases[opts{}] = false
|
testCases[opts{}] = false
|
||||||
testCases[opts{Limit: 100}] = false
|
testCases[opts{Limit: 100}] = false
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan}] = false
|
|
||||||
testCases[opts{ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Limit: 100}] = false
|
|
||||||
for opt, expectBypass := range testCases {
|
for opt, expectBypass := range testCases {
|
||||||
testGetListCacheBypass(t, storage.ListOptions{
|
testGetListCacheBypass(t, storage.ListOptions{
|
||||||
ResourceVersion: opt.ResourceVersion,
|
ResourceVersion: opt.ResourceVersion,
|
||||||
|
Loading…
Reference in New Issue
Block a user