From d28aba9d5d9ef2d3e9312a478cf7d9a2d310155d Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Mon, 11 Dec 2023 21:19:06 +0100 Subject: [PATCH 1/3] Add tests for KeyValueStoreNames prefix Signed-off-by: Tomasz Pietrek --- jetstream/test/kv_test.go | 3 +++ test/kv_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/jetstream/test/kv_test.go b/jetstream/test/kv_test.go index 788a31896..cc0b556cb 100644 --- a/jetstream/test/kv_test.go +++ b/jetstream/test/kv_test.go @@ -995,6 +995,9 @@ func TestListKeyValueStores(t *testing.T) { names := make([]string, 0) kvNames := js.KeyValueStoreNames(ctx) for name := range kvNames.Name() { + if strings.HasPrefix(name, "KV_") { + t.Fatalf("Expected name without KV_ prefix, got %q", name) + } names = append(names, name) } if kvNames.Error() != nil { diff --git a/test/kv_test.go b/test/kv_test.go index afa937de5..92de2c982 100644 --- a/test/kv_test.go +++ b/test/kv_test.go @@ -979,6 +979,9 @@ func TestListKeyValueStores(t *testing.T) { } names := make([]string, 0) for name := range js.KeyValueStoreNames() { + if strings.HasPrefix(name, "KV_") { + t.Fatalf("Expected name without KV_ prefix, got %q", name) + } names = append(names, name) } if len(names) != test.bucketsNum { From f2b67611816148a81838aaa3d03ae3a64adae51a Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Mon, 11 Dec 2023 21:20:33 +0100 Subject: [PATCH 2/3] Strip KV_ prefix from KeyValueStoreNames in `jetstream` package Signed-off-by: Tomasz Pietrek --- jetstream/kv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetstream/kv.go b/jetstream/kv.go index c16c57146..3f5f24aff 100644 --- a/jetstream/kv.go +++ b/jetstream/kv.go @@ -411,7 +411,7 @@ func (js *jetStream) KeyValueStoreNames(ctx context.Context) KeyValueNamesLister if !strings.HasPrefix(name, kvBucketNamePre) { continue } - res.kvNames <- name + res.kvNames <- strings.TrimPrefix(name, kvBucketNamePre) } if errors.Is(err, ErrEndOfData) { return From cdddae2434c4a0d226459c12cfbfa756ec9d02a1 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Mon, 11 Dec 2023 21:22:13 +0100 Subject: [PATCH 3/3] Strip KV_ prefix from old KV JS API Signed-off-by: Tomasz Pietrek --- kv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kv.go b/kv.go index ed4edc391..2e7ce6e55 100644 --- a/kv.go +++ b/kv.go @@ -1062,7 +1062,7 @@ func (js *js) KeyValueStoreNames() <-chan string { if !strings.HasPrefix(name, kvBucketNamePre) { continue } - ch <- name + ch <- strings.TrimPrefix(name, kvBucketNamePre) } } }()