mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #130616 from gnufied/fix-root-unit-test-ownership-perms
Fix unit tests for volume ownership
This commit is contained in:
commit
45fa12f8af
@ -332,16 +332,32 @@ func TestSetVolumeOwnershipMode(t *testing.T) {
|
|||||||
func TestProgressTracking(t *testing.T) {
|
func TestProgressTracking(t *testing.T) {
|
||||||
alwaysApplyPolicy := v1.FSGroupChangeAlways
|
alwaysApplyPolicy := v1.FSGroupChangeAlways
|
||||||
var expectedGID int64 = 9999
|
var expectedGID int64 = 9999
|
||||||
|
|
||||||
|
// capture original variable
|
||||||
|
originalfilePermissionChangeFunc := filePermissionChangeFunc
|
||||||
|
originalProgressReportDuration := progressReportDuration
|
||||||
|
originalfirstEventReportDuration := firstEventReportDuration
|
||||||
|
|
||||||
var permissionSleepDuration = 5 * time.Millisecond
|
var permissionSleepDuration = 5 * time.Millisecond
|
||||||
// how often to report the events
|
|
||||||
|
// Override how often progress is reported
|
||||||
progressReportDuration = 200 * time.Millisecond
|
progressReportDuration = 200 * time.Millisecond
|
||||||
|
// Override when first event about progress is reported
|
||||||
firstEventReportDuration = 50 * time.Millisecond
|
firstEventReportDuration = 50 * time.Millisecond
|
||||||
|
|
||||||
filePermissionChangeFunc = func(filename string, fsGroup *int64, _ bool, _ os.FileInfo) error {
|
// Override how permission change is applied, so as to artificially slow
|
||||||
t.Logf("Calling file permission change for %s with gid %d", filename, *fsGroup)
|
// permission change
|
||||||
|
filePermissionChangeFunc = func(filename string, fsGroup *int64, readonly bool, info os.FileInfo) error {
|
||||||
time.Sleep(permissionSleepDuration)
|
time.Sleep(permissionSleepDuration)
|
||||||
|
originalfilePermissionChangeFunc(filename, fsGroup, readonly, info)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
filePermissionChangeFunc = originalfilePermissionChangeFunc
|
||||||
|
progressReportDuration = originalProgressReportDuration
|
||||||
|
firstEventReportDuration = originalfirstEventReportDuration
|
||||||
|
})
|
||||||
|
|
||||||
pod := &v1.Pod{
|
pod := &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "pod1",
|
Name: "pod1",
|
||||||
|
Loading…
Reference in New Issue
Block a user