mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Merge pull request #92390 from neolit123/1.19-fix-long-upload-config-tests
kubeadm: remove negative test cases from TestUploadConfiguration
This commit is contained in:
commit
cb0ef9e623
@ -48,10 +48,8 @@ go_test(
|
||||
"//cmd/kubeadm/app/constants:go_default_library",
|
||||
"//cmd/kubeadm/app/util/config:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/testing:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -22,11 +22,9 @@ import (
|
||||
"testing"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
clientsetfake "k8s.io/client-go/kubernetes/fake"
|
||||
core "k8s.io/client-go/testing"
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
||||
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
|
||||
@ -37,10 +35,7 @@ import (
|
||||
func TestUploadConfiguration(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
errOnCreate error
|
||||
errOnUpdate error
|
||||
updateExisting bool
|
||||
errExpected bool
|
||||
verifyResult bool
|
||||
}{
|
||||
{
|
||||
@ -52,17 +47,6 @@ func TestUploadConfiguration(t *testing.T) {
|
||||
updateExisting: true,
|
||||
verifyResult: true,
|
||||
},
|
||||
{
|
||||
name: "unexpected errors for create should be returned",
|
||||
errOnCreate: apierrors.NewUnauthorized(""),
|
||||
errExpected: true,
|
||||
},
|
||||
{
|
||||
name: "update existing show report error if unexpected error for update is returned",
|
||||
errOnUpdate: apierrors.NewUnauthorized(""),
|
||||
updateExisting: true,
|
||||
errExpected: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t2 *testing.T) {
|
||||
@ -101,22 +85,12 @@ func TestUploadConfiguration(t *testing.T) {
|
||||
}
|
||||
|
||||
client := clientsetfake.NewSimpleClientset()
|
||||
if tt.errOnCreate != nil {
|
||||
client.PrependReactor("create", "configmaps", func(action core.Action) (bool, runtime.Object, error) {
|
||||
return true, nil, tt.errOnCreate
|
||||
})
|
||||
}
|
||||
// For idempotent test, we check the result of the second call.
|
||||
if err := UploadConfiguration(cfg, client); !tt.updateExisting && (err != nil) != tt.errExpected {
|
||||
t2.Fatalf("UploadConfiguration() error = %v, wantErr %v", err, tt.errExpected)
|
||||
if err := UploadConfiguration(cfg, client); err != nil {
|
||||
t2.Fatalf("UploadConfiguration() error = %v", err)
|
||||
}
|
||||
if tt.updateExisting {
|
||||
if tt.errOnUpdate != nil {
|
||||
client.PrependReactor("update", "configmaps", func(action core.Action) (bool, runtime.Object, error) {
|
||||
return true, nil, tt.errOnUpdate
|
||||
})
|
||||
}
|
||||
if err := UploadConfiguration(cfg, client); (err != nil) != tt.errExpected {
|
||||
if err := UploadConfiguration(cfg, client); err != nil {
|
||||
t2.Fatalf("UploadConfiguration() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user