Merge pull request #79924 from cwdsuzhou/July/projected_test_cleanup

Fix projected volume test clean up
This commit is contained in:
Kubernetes Prow Robot 2019-07-10 18:49:44 -07:00 committed by GitHub
commit 8a1c9e2b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,49 +245,52 @@ func TestCollectDataWithSecret(t *testing.T) {
}
for _, tc := range cases {
testNamespace := "test_projected_namespace"
tc.secret.ObjectMeta = metav1.ObjectMeta{
Namespace: testNamespace,
Name: tc.name,
}
t.Run(tc.name, func(t *testing.T) {
source := makeProjection(tc.name, tc.mode, "secret")
source.Sources[0].Secret.Items = tc.mappings
source.Sources[0].Secret.Optional = &tc.optional
testNamespace := "test_projected_namespace"
tc.secret.ObjectMeta = metav1.ObjectMeta{
Namespace: testNamespace,
Name: tc.name,
}
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)
source := makeProjection(tc.name, tc.mode, "secret")
source.Sources[0].Secret.Items = tc.mappings
source.Sources[0].Secret.Optional = &tc.optional
var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{
sources: source.Sources,
podUID: pod.UID,
plugin: &projectedPlugin{
host: host,
getSecret: host.GetSecretFunc(),
testPodUID := types.UID("test_pod_uid")
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
client := fake.NewSimpleClientset(tc.secret)
tempDir, host := newTestHost(t, client)
defer os.RemoveAll(tempDir)
var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{
sources: source.Sources,
podUID: pod.UID,
plugin: &projectedPlugin{
host: host,
getSecret: host.GetSecretFunc(),
},
},
},
source: *source,
pod: pod,
}
source: *source,
pod: pod,
}
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)
}
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)
}
})
}
}
@ -492,49 +495,51 @@ func TestCollectDataWithConfigMap(t *testing.T) {
},
}
for _, tc := range cases {
testNamespace := "test_projected_namespace"
tc.configMap.ObjectMeta = metav1.ObjectMeta{
Namespace: testNamespace,
Name: tc.name,
}
t.Run(tc.name, func(t *testing.T) {
testNamespace := "test_projected_namespace"
tc.configMap.ObjectMeta = metav1.ObjectMeta{
Namespace: testNamespace,
Name: tc.name,
}
source := makeProjection(tc.name, tc.mode, "configMap")
source.Sources[0].ConfigMap.Items = tc.mappings
source.Sources[0].ConfigMap.Optional = &tc.optional
source := makeProjection(tc.name, tc.mode, "configMap")
source.Sources[0].ConfigMap.Items = tc.mappings
source.Sources[0].ConfigMap.Optional = &tc.optional
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)
var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{
sources: source.Sources,
podUID: pod.UID,
plugin: &projectedPlugin{
host: host,
getConfigMap: host.GetConfigMapFunc(),
testPodUID := types.UID("test_pod_uid")
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
client := fake.NewSimpleClientset(tc.configMap)
tempDir, host := newTestHost(t, client)
defer os.RemoveAll(tempDir)
var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{
sources: source.Sources,
podUID: pod.UID,
plugin: &projectedPlugin{
host: host,
getConfigMap: host.GetConfigMapFunc(),
},
},
},
source: *source,
pod: pod,
}
source: *source,
pod: pod,
}
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)
}
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)
}
})
}
}
@ -670,39 +675,42 @@ func TestCollectDataWithDownwardAPI(t *testing.T) {
}
for _, tc := range cases {
source := makeProjection("", tc.mode, "downwardAPI")
source.Sources[0].DownwardAPI.Items = tc.volumeFile
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)
var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{
sources: source.Sources,
podUID: tc.pod.UID,
plugin: &projectedPlugin{
host: host,
client := fake.NewSimpleClientset(tc.pod)
tempDir, host := newTestHost(t, client)
defer os.RemoveAll(tempDir)
var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{
sources: source.Sources,
podUID: tc.pod.UID,
plugin: &projectedPlugin{
host: host,
},
},
},
source: *source,
pod: tc.pod,
}
source: *source,
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
}))
_, host := newTestHost(t, client)
tempDir, host := newTestHost(t, client)
defer os.RemoveAll(tempDir)
var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{