Skip to content

Commit 45fa12f

Browse files
authored
Merge pull request kubernetes#130616 from gnufied/fix-root-unit-test-ownership-perms
Fix unit tests for volume ownership
2 parents 0f7becb + 5a7697d commit 45fa12f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

pkg/volume/volume_linux_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,32 @@ func TestSetVolumeOwnershipMode(t *testing.T) {
332332
func TestProgressTracking(t *testing.T) {
333333
alwaysApplyPolicy := v1.FSGroupChangeAlways
334334
var expectedGID int64 = 9999
335+
336+
// capture original variable
337+
originalfilePermissionChangeFunc := filePermissionChangeFunc
338+
originalProgressReportDuration := progressReportDuration
339+
originalfirstEventReportDuration := firstEventReportDuration
340+
335341
var permissionSleepDuration = 5 * time.Millisecond
336-
// how often to report the events
342+
343+
// Override how often progress is reported
337344
progressReportDuration = 200 * time.Millisecond
345+
// Override when first event about progress is reported
338346
firstEventReportDuration = 50 * time.Millisecond
339347

340-
filePermissionChangeFunc = func(filename string, fsGroup *int64, _ bool, _ os.FileInfo) error {
341-
t.Logf("Calling file permission change for %s with gid %d", filename, *fsGroup)
348+
// Override how permission change is applied, so as to artificially slow
349+
// permission change
350+
filePermissionChangeFunc = func(filename string, fsGroup *int64, readonly bool, info os.FileInfo) error {
342351
time.Sleep(permissionSleepDuration)
352+
originalfilePermissionChangeFunc(filename, fsGroup, readonly, info)
343353
return nil
344354
}
355+
t.Cleanup(func() {
356+
filePermissionChangeFunc = originalfilePermissionChangeFunc
357+
progressReportDuration = originalProgressReportDuration
358+
firstEventReportDuration = originalfirstEventReportDuration
359+
})
360+
345361
pod := &v1.Pod{
346362
ObjectMeta: metav1.ObjectMeta{
347363
Name: "pod1",

0 commit comments

Comments
 (0)