mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #79924 from cwdsuzhou/July/projected_test_cleanup
Fix projected volume test clean up
This commit is contained in:
commit
8a1c9e2b41
@ -245,49 +245,52 @@ func TestCollectDataWithSecret(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
testNamespace := "test_projected_namespace"
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
tc.secret.ObjectMeta = metav1.ObjectMeta{
|
|
||||||
Namespace: testNamespace,
|
|
||||||
Name: tc.name,
|
|
||||||
}
|
|
||||||
|
|
||||||
source := makeProjection(tc.name, tc.mode, "secret")
|
testNamespace := "test_projected_namespace"
|
||||||
source.Sources[0].Secret.Items = tc.mappings
|
tc.secret.ObjectMeta = metav1.ObjectMeta{
|
||||||
source.Sources[0].Secret.Optional = &tc.optional
|
Namespace: testNamespace,
|
||||||
|
Name: tc.name,
|
||||||
|
}
|
||||||
|
|
||||||
testPodUID := types.UID("test_pod_uid")
|
source := makeProjection(tc.name, tc.mode, "secret")
|
||||||
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
|
source.Sources[0].Secret.Items = tc.mappings
|
||||||
client := fake.NewSimpleClientset(tc.secret)
|
source.Sources[0].Secret.Optional = &tc.optional
|
||||||
_, host := newTestHost(t, client)
|
|
||||||
|
|
||||||
var myVolumeMounter = projectedVolumeMounter{
|
testPodUID := types.UID("test_pod_uid")
|
||||||
projectedVolume: &projectedVolume{
|
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
|
||||||
sources: source.Sources,
|
client := fake.NewSimpleClientset(tc.secret)
|
||||||
podUID: pod.UID,
|
tempDir, host := newTestHost(t, client)
|
||||||
plugin: &projectedPlugin{
|
defer os.RemoveAll(tempDir)
|
||||||
host: host,
|
var myVolumeMounter = projectedVolumeMounter{
|
||||||
getSecret: host.GetSecretFunc(),
|
projectedVolume: &projectedVolume{
|
||||||
|
sources: source.Sources,
|
||||||
|
podUID: pod.UID,
|
||||||
|
plugin: &projectedPlugin{
|
||||||
|
host: host,
|
||||||
|
getSecret: host.GetSecretFunc(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
source: *source,
|
||||||
source: *source,
|
pod: pod,
|
||||||
pod: pod,
|
}
|
||||||
}
|
|
||||||
|
|
||||||
actualPayload, err := myVolumeMounter.collectData()
|
actualPayload, err := myVolumeMounter.collectData()
|
||||||
if err != nil && tc.success {
|
if err != nil && tc.success {
|
||||||
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if err == nil && !tc.success {
|
if err == nil && !tc.success {
|
||||||
t.Errorf("%v: unexpected success making payload", tc.name)
|
t.Errorf("%v: unexpected success making payload", tc.name)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if !tc.success {
|
if !tc.success {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,49 +495,51 @@ func TestCollectDataWithConfigMap(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
testNamespace := "test_projected_namespace"
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
tc.configMap.ObjectMeta = metav1.ObjectMeta{
|
testNamespace := "test_projected_namespace"
|
||||||
Namespace: testNamespace,
|
tc.configMap.ObjectMeta = metav1.ObjectMeta{
|
||||||
Name: tc.name,
|
Namespace: testNamespace,
|
||||||
}
|
Name: tc.name,
|
||||||
|
}
|
||||||
|
|
||||||
source := makeProjection(tc.name, tc.mode, "configMap")
|
source := makeProjection(tc.name, tc.mode, "configMap")
|
||||||
source.Sources[0].ConfigMap.Items = tc.mappings
|
source.Sources[0].ConfigMap.Items = tc.mappings
|
||||||
source.Sources[0].ConfigMap.Optional = &tc.optional
|
source.Sources[0].ConfigMap.Optional = &tc.optional
|
||||||
|
|
||||||
testPodUID := types.UID("test_pod_uid")
|
testPodUID := types.UID("test_pod_uid")
|
||||||
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
|
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
|
||||||
client := fake.NewSimpleClientset(tc.configMap)
|
client := fake.NewSimpleClientset(tc.configMap)
|
||||||
_, host := newTestHost(t, client)
|
tempDir, host := newTestHost(t, client)
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
var myVolumeMounter = projectedVolumeMounter{
|
var myVolumeMounter = projectedVolumeMounter{
|
||||||
projectedVolume: &projectedVolume{
|
projectedVolume: &projectedVolume{
|
||||||
sources: source.Sources,
|
sources: source.Sources,
|
||||||
podUID: pod.UID,
|
podUID: pod.UID,
|
||||||
plugin: &projectedPlugin{
|
plugin: &projectedPlugin{
|
||||||
host: host,
|
host: host,
|
||||||
getConfigMap: host.GetConfigMapFunc(),
|
getConfigMap: host.GetConfigMapFunc(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
source: *source,
|
||||||
source: *source,
|
pod: pod,
|
||||||
pod: pod,
|
}
|
||||||
}
|
|
||||||
|
|
||||||
actualPayload, err := myVolumeMounter.collectData()
|
actualPayload, err := myVolumeMounter.collectData()
|
||||||
if err != nil && tc.success {
|
if err != nil && tc.success {
|
||||||
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if err == nil && !tc.success {
|
if err == nil && !tc.success {
|
||||||
t.Errorf("%v: unexpected success making payload", tc.name)
|
t.Errorf("%v: unexpected success making payload", tc.name)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if !tc.success {
|
if !tc.success {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -670,39 +675,42 @@ func TestCollectDataWithDownwardAPI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
source := makeProjection("", tc.mode, "downwardAPI")
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
source.Sources[0].DownwardAPI.Items = tc.volumeFile
|
source := makeProjection("", tc.mode, "downwardAPI")
|
||||||
|
source.Sources[0].DownwardAPI.Items = tc.volumeFile
|
||||||
|
|
||||||
client := fake.NewSimpleClientset(tc.pod)
|
client := fake.NewSimpleClientset(tc.pod)
|
||||||
_, host := newTestHost(t, client)
|
tempDir, host := newTestHost(t, client)
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
var myVolumeMounter = projectedVolumeMounter{
|
var myVolumeMounter = projectedVolumeMounter{
|
||||||
projectedVolume: &projectedVolume{
|
projectedVolume: &projectedVolume{
|
||||||
sources: source.Sources,
|
sources: source.Sources,
|
||||||
podUID: tc.pod.UID,
|
podUID: tc.pod.UID,
|
||||||
plugin: &projectedPlugin{
|
plugin: &projectedPlugin{
|
||||||
host: host,
|
host: host,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
source: *source,
|
||||||
source: *source,
|
pod: tc.pod,
|
||||||
pod: tc.pod,
|
}
|
||||||
}
|
|
||||||
|
actualPayload, err := myVolumeMounter.collectData()
|
||||||
|
if err != nil && tc.success {
|
||||||
|
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err == nil && !tc.success {
|
||||||
|
t.Errorf("%v: unexpected success making payload", tc.name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !tc.success {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
||||||
|
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
actualPayload, err := myVolumeMounter.collectData()
|
|
||||||
if err != nil && tc.success {
|
|
||||||
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err == nil && !tc.success {
|
|
||||||
t.Errorf("%v: unexpected success making payload", tc.name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !tc.success {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
|
||||||
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,7 +795,8 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
|
|||||||
return true, tr, nil
|
return true, tr, nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
_, host := newTestHost(t, client)
|
tempDir, host := newTestHost(t, client)
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
var myVolumeMounter = projectedVolumeMounter{
|
var myVolumeMounter = projectedVolumeMounter{
|
||||||
projectedVolume: &projectedVolume{
|
projectedVolume: &projectedVolume{
|
||||||
|
Loading…
Reference in New Issue
Block a user