Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.

Commit ec5dbc6

Browse files
author
lianghuan
committed
222
1 parent 012cb48 commit ec5dbc6

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

flatten/store.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ func (s *LayeredStorage) MapKeys(key string, result map[string]struct{}) bool {
433433
func (s *LayeredStorage) SliceEntries(key string, result map[string]string) bool {
434434
for _, arr := range s.layers {
435435
for _, source := range arr {
436+
if _, ok := source.Value(key); ok {
437+
return false
438+
}
436439
if source.SliceEntries(key, result) {
437440
return true
438441
}

flatten/store_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,30 @@ func TestLayeredStorage(t *testing.T) {
537537
assert.That(t, result["users[0].name"]).Equal("Override")
538538
})
539539

540+
t.Run("SliceEntries stops at higher priority scalar value", func(t *testing.T) {
541+
s := &LayeredStorage{}
542+
543+
defaultLayer := NewProperties(map[string]string{
544+
"users[0]": "Default",
545+
"users[1]": "User1",
546+
})
547+
s.AddStorage(StorageDefault, NewPropertiesStorage(defaultLayer), "default")
548+
549+
cmdlineLayer := NewProperties(map[string]string{
550+
"users": "Override1,Override2",
551+
})
552+
s.AddStorage(StorageCommandLine, NewPropertiesStorage(cmdlineLayer), "cmdline")
553+
554+
result := make(map[string]string)
555+
found := s.SliceEntries("users", result)
556+
557+
assert.That(t, found).False()
558+
assert.That(t, len(result)).Equal(0)
559+
val, ok := s.Value("users")
560+
assert.That(t, ok).True()
561+
assert.That(t, val).Equal("Override1,Override2")
562+
})
563+
540564
t.Run("multiple sources in same layer", func(t *testing.T) {
541565
s := &LayeredStorage{}
542566

0 commit comments

Comments
 (0)