Skip to content

Commit af7478b

Browse files
committed
enforce log-file strictness and centralize log filename parsing
1 parent a4bbd53 commit af7478b

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

tools/integration_tests/inactive_stream_timeout/setup_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/mounting/static_mounting"
3434
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
3535
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/test_suite"
36+
"github.com/stretchr/testify/require"
3637
)
3738

3839
const (
@@ -93,9 +94,7 @@ func hasInactiveReaderClosedLogLineInLogFile(t *testing.T, objectName, logFile s
9394
expectedMsgSubstring := fmt.Sprintf("Closing reader for object %q due to inactivity.", objectName)
9495

9596
file, err := os.Open(logFile)
96-
if err != nil {
97-
return "", fmt.Errorf("failed to open log file: %w", err)
98-
}
97+
require.NoError(t, err, "failed to open log file")
9998
defer file.Close()
10099

101100
scanner := bufio.NewScanner(file)

tools/integration_tests/util/setup/setup.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,19 @@ func OverrideFilePathsInFlagSet(t *test_suite.TestConfig, GCSFuseTempDirPath str
847847

848848
func ParseLogFileFromFlags(flags []string) string {
849849
for _, flagStr := range flags {
850+
flagStr = strings.ReplaceAll(flagStr, ",", " ")
850851
parts := strings.Fields(flagStr)
851852
for _, part := range parts {
852853
if strings.HasPrefix(part, "--log-file=") {
853-
// Get just the filename from the path
854-
return path.Base(strings.TrimPrefix(part, "--log-file="))
854+
logPath := strings.TrimPrefix(part, "--log-file=")
855+
if logPath == "" {
856+
continue
857+
}
858+
fileName := path.Base(logPath)
859+
if !strings.HasSuffix(fileName, ".log") {
860+
fileName += ".log"
861+
}
862+
return fileName
855863
}
856864
}
857865
}
@@ -861,14 +869,25 @@ func ParseLogFileFromFlags(flags []string) string {
861869
func SetUpLogFilePath(flags []string, GKETempDir string, OldGKElogFilePath string, cfg *test_suite.TestConfig) {
862870
var logFilePath string
863871
parsedLogFileName := ParseLogFileFromFlags(flags)
864-
if cfg.GKEMountedDirectory != "" { // GKE path
865-
logFilePath = path.Join(GKETempDir, parsedLogFileName) + ".log"
872+
873+
// Infer log filename directly from the parsed config block.
874+
if parsedLogFileName == "" && cfg != nil && len(cfg.Configs) > 0 {
875+
parsedLogFileName = ParseLogFileFromFlags(cfg.Configs[0].Flags)
876+
}
877+
878+
// Default logFile name.
879+
if parsedLogFileName == "" {
880+
parsedLogFileName = "gcsfuse-tmp.log"
881+
}
882+
883+
if cfg != nil && cfg.GKEMountedDirectory != "" { // GKE path
884+
logFilePath = path.Join(GKETempDir, parsedLogFileName)
866885
if ConfigFile() == "" {
867886
// TODO: clean this up when GKE test migration completes.
868887
logFilePath = OldGKElogFilePath
869888
}
870889
} else {
871-
logFilePath = path.Join(TestDir(), GKETempDir, parsedLogFileName) + ".log"
890+
logFilePath = path.Join(TestDir(), GKETempDir, parsedLogFileName)
872891
}
873892
cfg.LogFile = logFilePath
874893
SetLogFile(logFilePath)

0 commit comments

Comments
 (0)