Skip to content

Commit

Permalink
Merge pull request kubernetes#79924 from cwdsuzhou/July/projected_tes…
Browse files Browse the repository at this point in the history
…t_cleanup

Fix projected volume test clean up
  • Loading branch information
k8s-ci-robot authored Jul 11, 2019
2 parents 8341344 + 94a2a42 commit 8a1c9e2
Showing 1 changed file with 121 additions and 112 deletions.
233 changes: 121 additions & 112 deletions pkg/volume/projected/projected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

testNamespace := "test_projected_namespace"
tc.secret.ObjectMeta = metav1.ObjectMeta{
Namespace: testNamespace,
Name: tc.name,
}

source := makeProjection(tc.name, tc.mode, "secret")
source.Sources[0].Secret.Items = tc.mappings
source.Sources[0].Secret.Optional = &tc.optional

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)

var myVolumeMounter = projectedVolumeMounter{
projectedVolume: &projectedVolume{
sources: source.Sources,
podUID: pod.UID,
plugin: &projectedPlugin{
host: host,
getSecret: host.GetSecretFunc(),
source := makeProjection(tc.name, tc.mode, "secret")
source.Sources[0].Secret.Items = tc.mappings
source.Sources[0].Secret.Optional = &tc.optional

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)
}
})
}
}

Expand Down Expand Up @@ -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

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(),
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)
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)
}
})
}
}

Expand Down Expand Up @@ -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

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,
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)
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)
}
}
}

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 8a1c9e2

Please sign in to comment.