From 92a9abede25be33dba14ab1264ff9a8b8f66cff6 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 25 Jul 2024 23:53:35 +0300 Subject: [PATCH] node/config: allow "1b" config values for memory amount It was not used in practice before, so no issues were opened, or tests were written, but it still looks like a valid configuration value. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + cmd/neofs-node/config/cast.go | 2 +- cmd/neofs-node/config/cast_test.go | 2 ++ cmd/neofs-node/config/test/config.json | 2 ++ cmd/neofs-node/config/test/config.yaml | 2 ++ 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2306a18ccd..7ae4e09ed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Changelog for NeoFS Node ### Fixed - Control service's Drop call does not clean metabase (#2822) +- It was impossible to specify memory amount as "1b" (one byte) in config, default was used instead (#2899) ### Changed - neofs-cli allows several objects deletion at a time (#2774) diff --git a/cmd/neofs-node/config/cast.go b/cmd/neofs-node/config/cast.go index cf0017ca54..9036c3ab0a 100644 --- a/cmd/neofs-node/config/cast.go +++ b/cmd/neofs-node/config/cast.go @@ -199,7 +199,7 @@ func parseSizeInBytes(sizeStr string) uint64 { if sizeStr[lastChar] == 'b' || sizeStr[lastChar] == 'B' { lastChar-- } - if lastChar > 0 { + if lastChar >= 0 { switch unicode.ToLower(rune(sizeStr[lastChar])) { case 'k': multiplier = 1 << 10 diff --git a/cmd/neofs-node/config/cast_test.go b/cmd/neofs-node/config/cast_test.go index 85b6e1e95a..13173b02af 100644 --- a/cmd/neofs-node/config/cast_test.go +++ b/cmd/neofs-node/config/cast_test.go @@ -134,6 +134,8 @@ func TestSizeInBytes(t *testing.T) { require.EqualValues(t, tb/2, config.SizeInBytesSafe(c, "size_float")) require.EqualValues(t, uint64(14*gb+(gb*123/1000/mb*mb)), config.SizeInBytesSafe(c, "size_float_big")) require.EqualValues(t, 2048, config.SizeInBytesSafe(c, "size_bytes")) + require.EqualValues(t, 1, config.SizeInBytesSafe(c, "size_bytes_single_char")) + require.EqualValues(t, 1, config.SizeInBytesSafe(c, "size_bytes_single_char_no_space")) require.EqualValues(t, 123456, config.SizeInBytesSafe(c, "size_bytes_no_suffix")) }) } diff --git a/cmd/neofs-node/config/test/config.json b/cmd/neofs-node/config/test/config.json index 45635c7ab1..f2505f42f9 100644 --- a/cmd/neofs-node/config/test/config.json +++ b/cmd/neofs-node/config/test/config.json @@ -58,6 +58,8 @@ "size_float_big": "14.123 gb", "size_i_am_not_very_clever": "12.12345678", "size_bytes": "2048b", + "size_bytes_single_char": "1 b", + "size_bytes_single_char_no_space": "1b", "size_bytes_no_suffix": 123456 }, diff --git a/cmd/neofs-node/config/test/config.yaml b/cmd/neofs-node/config/test/config.yaml index 102c045a1c..d48a07cb21 100644 --- a/cmd/neofs-node/config/test/config.yaml +++ b/cmd/neofs-node/config/test/config.yaml @@ -51,6 +51,8 @@ sizes: size_float_big: 14.123 gb size_i_am_not_very_clever: 12.12345678 size_bytes: 2048b + size_bytes_single_char: 1 b + size_bytes_single_char_no_space: 1b size_bytes_no_suffix: 123456 with_default: