Move GetFileModeRegex to e2e/common

because the function is used at e2e/common tests only.
This commit is contained in:
Kenichi Omichi
2020-03-23 23:13:39 +00:00
parent 0641e0c6d8
commit 5f81f5b96c
6 changed files with 32 additions and 31 deletions

View File

@@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"
"os"
"text/template"
"time"
@@ -222,3 +223,24 @@ func setPodNonRootUser(pod *v1.Pod) {
pod.Spec.SecurityContext.RunAsUser = &nonRootTestUserID
}
}
// getFileModeRegex returns a file mode related regex which should be matched by the mounttest pods' output.
// If the given mask is nil, then the regex will contain the default OS file modes, which are 0644 for Linux and 0775 for Windows.
func getFileModeRegex(filePath string, mask *int32) string {
var (
linuxMask int32
windowsMask int32
)
if mask == nil {
linuxMask = int32(0644)
windowsMask = int32(0775)
} else {
linuxMask = *mask
windowsMask = *mask
}
linuxOutput := fmt.Sprintf("mode of file \"%s\": %v", filePath, os.FileMode(linuxMask))
windowsOutput := fmt.Sprintf("mode of Windows file \"%v\": %s", filePath, os.FileMode(windowsMask))
return fmt.Sprintf("(%s|%s)", linuxOutput, windowsOutput)
}