mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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,6 +245,8 @@ func TestCollectDataWithSecret(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
testNamespace := "test_projected_namespace"
|
||||
tc.secret.ObjectMeta = metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
@ -258,8 +260,8 @@ func TestCollectDataWithSecret(t *testing.T) {
|
||||
testPodUID := types.UID("test_pod_uid")
|
||||
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
|
||||
client := fake.NewSimpleClientset(tc.secret)
|
||||
_, host := newTestHost(t, client)
|
||||
|
||||
tempDir, host := newTestHost(t, client)
|
||||
defer os.RemoveAll(tempDir)
|
||||
var myVolumeMounter = projectedVolumeMounter{
|
||||
projectedVolume: &projectedVolume{
|
||||
sources: source.Sources,
|
||||
@ -276,18 +278,19 @@ func TestCollectDataWithSecret(t *testing.T) {
|
||||
actualPayload, err := myVolumeMounter.collectData()
|
||||
if err != nil && tc.success {
|
||||
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
if err == nil && !tc.success {
|
||||
t.Errorf("%v: unexpected success making payload", tc.name)
|
||||
continue
|
||||
return
|
||||
}
|
||||
if !tc.success {
|
||||
continue
|
||||
return
|
||||
}
|
||||
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -492,6 +495,7 @@ func TestCollectDataWithConfigMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
testNamespace := "test_projected_namespace"
|
||||
tc.configMap.ObjectMeta = metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
@ -505,8 +509,8 @@ func TestCollectDataWithConfigMap(t *testing.T) {
|
||||
testPodUID := types.UID("test_pod_uid")
|
||||
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
|
||||
client := fake.NewSimpleClientset(tc.configMap)
|
||||
_, host := newTestHost(t, client)
|
||||
|
||||
tempDir, host := newTestHost(t, client)
|
||||
defer os.RemoveAll(tempDir)
|
||||
var myVolumeMounter = projectedVolumeMounter{
|
||||
projectedVolume: &projectedVolume{
|
||||
sources: source.Sources,
|
||||
@ -523,18 +527,19 @@ func TestCollectDataWithConfigMap(t *testing.T) {
|
||||
actualPayload, err := myVolumeMounter.collectData()
|
||||
if err != nil && tc.success {
|
||||
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
if err == nil && !tc.success {
|
||||
t.Errorf("%v: unexpected success making payload", tc.name)
|
||||
continue
|
||||
return
|
||||
}
|
||||
if !tc.success {
|
||||
continue
|
||||
return
|
||||
}
|
||||
if e, a := tc.payload, actualPayload; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%v: expected and actual payload do not match", tc.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -670,12 +675,13 @@ func TestCollectDataWithDownwardAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
source := makeProjection("", tc.mode, "downwardAPI")
|
||||
source.Sources[0].DownwardAPI.Items = tc.volumeFile
|
||||
|
||||
client := fake.NewSimpleClientset(tc.pod)
|
||||
_, host := newTestHost(t, client)
|
||||
|
||||
tempDir, host := newTestHost(t, client)
|
||||
defer os.RemoveAll(tempDir)
|
||||
var myVolumeMounter = projectedVolumeMounter{
|
||||
projectedVolume: &projectedVolume{
|
||||
sources: source.Sources,
|
||||
@ -691,18 +697,20 @@ func TestCollectDataWithDownwardAPI(t *testing.T) {
|
||||
actualPayload, err := myVolumeMounter.collectData()
|
||||
if err != nil && tc.success {
|
||||
t.Errorf("%v: unexpected failure making payload: %v", tc.name, err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
if err == nil && !tc.success {
|
||||
t.Errorf("%v: unexpected success making payload", tc.name)
|
||||
continue
|
||||
return
|
||||
}
|
||||
if !tc.success {
|
||||
continue
|
||||
return
|
||||
}
|
||||
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
|
||||
}))
|
||||
|
||||
_, host := newTestHost(t, client)
|
||||
tempDir, host := newTestHost(t, client)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
var myVolumeMounter = projectedVolumeMounter{
|
||||
projectedVolume: &projectedVolume{
|
||||
|
Loading…
Reference in New Issue
Block a user