From 366ee531bb628e5de470dd0b072ba46b997c37d1 Mon Sep 17 00:00:00 2001 From: Ali Date: Tue, 14 Apr 2026 01:21:26 +0500 Subject: [PATCH 1/4] util/runtime: let TestFsType tolerate filesystems absent from FsType map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FsType() returns the known magic-name string when the filesystem is present in its internal map, and falls back to strconv.FormatInt(..., 16) otherwise. The test was asserting the *MAGIC regex only, so it failed whenever it happened to run on a filesystem not yet mapped — the downstream Arch Linux packager hit this with a btrfs subvolume. Extend the regex to accept either a magic-name or the numeric lowercase-hex fallback, keeping the test stable across OS upgrades and exotic filesystems. Fixes #18471 Signed-off-by: Ali --- util/runtime/statfs_unix_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/runtime/statfs_unix_test.go b/util/runtime/statfs_unix_test.go index 563bd1dfa6..4b9878f8bd 100644 --- a/util/runtime/statfs_unix_test.go +++ b/util/runtime/statfs_unix_test.go @@ -23,7 +23,12 @@ import ( "github.com/stretchr/testify/require" ) -var regexpFsType = regexp.MustCompile("^[A-Z][A-Z0-9_]*_MAGIC$") +// regexpFsType matches either a known magic-number constant name (e.g. +// EXT4_SUPER_MAGIC) or the lowercase-hex numeric fallback that FsType +// returns for filesystems not present in its table. The numeric fallback +// branch keeps the test green on machines that run on filesystems the +// map hasn't been updated for yet (see prometheus/prometheus#18471). +var regexpFsType = regexp.MustCompile("^([A-Z][A-Z0-9_]*_MAGIC|[0-9a-f]+)$") func TestFsType(t *testing.T) { var fsType string From 48f4a41e3892e4a5c9b5b01b4a2eb0dfe034bfae Mon Sep 17 00:00:00 2001 From: Ali Date: Tue, 14 Apr 2026 16:49:46 +0500 Subject: [PATCH 2/4] util/runtime: skip TestFsType on unknown filesystems instead of accepting hex format Rather than widening the assertion to accept raw hex codes, skip the strict _MAGIC format check with t.Skipf when the filesystem is not in the known map. The test still exercises the error paths and will run fully on standard Linux/macOS filesystems. Fixes prometheus/prometheus#18471 Signed-off-by: Ali --- util/runtime/statfs_unix_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/util/runtime/statfs_unix_test.go b/util/runtime/statfs_unix_test.go index 4b9878f8bd..45e7d0b863 100644 --- a/util/runtime/statfs_unix_test.go +++ b/util/runtime/statfs_unix_test.go @@ -17,19 +17,12 @@ package runtime import ( "os" + "strings" "testing" - "github.com/grafana/regexp" "github.com/stretchr/testify/require" ) -// regexpFsType matches either a known magic-number constant name (e.g. -// EXT4_SUPER_MAGIC) or the lowercase-hex numeric fallback that FsType -// returns for filesystems not present in its table. The numeric fallback -// branch keeps the test green on machines that run on filesystems the -// map hasn't been updated for yet (see prometheus/prometheus#18471). -var regexpFsType = regexp.MustCompile("^([A-Z][A-Z0-9_]*_MAGIC|[0-9a-f]+)$") - func TestFsType(t *testing.T) { var fsType string @@ -37,7 +30,14 @@ func TestFsType(t *testing.T) { require.NoError(t, err) fsType = FsType(path) - require.Regexp(t, regexpFsType, fsType) + // If FsType returns a hex string the filesystem is not in the known map. + // Skip rather than fail so that CI on unusual filesystems does not + // spuriously break. The test is still exercised on known filesystems. + // See prometheus/prometheus#18471. + if !strings.Contains(fsType, "_MAGIC") { + t.Skipf("filesystem type %q not in known map, skipping strict format check", fsType) + } + require.Contains(t, fsType, "_MAGIC") fsType = FsType("/no/where/to/be/found") require.Equal(t, "0", fsType) From 6994b4cb4e70f6369a577723c446cc4a5f94f446 Mon Sep 17 00:00:00 2001 From: alliasgher Date: Tue, 14 Apr 2026 20:26:13 +0500 Subject: [PATCH 3/4] util/runtime: simplify TestFsType to check != 0 instead of _MAGIC Signed-off-by: alliasgher --- util/runtime/statfs_unix_test.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/util/runtime/statfs_unix_test.go b/util/runtime/statfs_unix_test.go index 45e7d0b863..3b3072f660 100644 --- a/util/runtime/statfs_unix_test.go +++ b/util/runtime/statfs_unix_test.go @@ -17,7 +17,6 @@ package runtime import ( "os" - "strings" "testing" "github.com/stretchr/testify/require" @@ -29,15 +28,11 @@ func TestFsType(t *testing.T) { path, err := os.Getwd() require.NoError(t, err) + // FsType returns a named constant (e.g. EXT4_SUPER_MAGIC) for known + // filesystems, or a lowercase-hex fallback for unknown ones. Either way + // the result must be non-zero for a real path. See #18471. fsType = FsType(path) - // If FsType returns a hex string the filesystem is not in the known map. - // Skip rather than fail so that CI on unusual filesystems does not - // spuriously break. The test is still exercised on known filesystems. - // See prometheus/prometheus#18471. - if !strings.Contains(fsType, "_MAGIC") { - t.Skipf("filesystem type %q not in known map, skipping strict format check", fsType) - } - require.Contains(t, fsType, "_MAGIC") + require.NotEqual(t, "0", fsType) fsType = FsType("/no/where/to/be/found") require.Equal(t, "0", fsType) From ae063a499a67c00978d25f1b2e4bf0185ad6dc82 Mon Sep 17 00:00:00 2001 From: alliasgher Date: Wed, 15 Apr 2026 15:54:02 +0500 Subject: [PATCH 4/4] util/runtime: simplify TestFsType comment per review Remove issue reference and trim the comment down to the assertion's intent, per @roidelapluie review. Signed-off-by: alliasgher --- util/runtime/statfs_unix_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/util/runtime/statfs_unix_test.go b/util/runtime/statfs_unix_test.go index 3b3072f660..3adff62120 100644 --- a/util/runtime/statfs_unix_test.go +++ b/util/runtime/statfs_unix_test.go @@ -28,9 +28,7 @@ func TestFsType(t *testing.T) { path, err := os.Getwd() require.NoError(t, err) - // FsType returns a named constant (e.g. EXT4_SUPER_MAGIC) for known - // filesystems, or a lowercase-hex fallback for unknown ones. Either way - // the result must be non-zero for a real path. See #18471. + // A real path must yield a non-zero filesystem type. fsType = FsType(path) require.NotEqual(t, "0", fsType)