Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 7b42179

Browse files
authored
Merge pull request #179 from EventStore/w1am/add-missing-custom-properties-getter-in-stream-metadata
Add CustomProperty and CustomProperties method to StreamMetadata
2 parents 8b18bf4 + 2f20097 commit 7b42179

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

esdb/types.go

+10
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ func (m *StreamMetadata) StreamAcl() *Acl {
267267
return nil
268268
}
269269

270+
// CustomProperty The custom property value for the given key.
271+
func (m *StreamMetadata) CustomProperty(key string) interface{} {
272+
return m.customProperties[key]
273+
}
274+
275+
// CustomProperties returns all custom properties.
276+
func (m *StreamMetadata) CustomProperties() map[string]interface{} {
277+
return m.customProperties
278+
}
279+
270280
// IsUserStreamAcl Checks if the ACL is set to users default.
271281
func (m *StreamMetadata) IsUserStreamAcl() bool {
272282
acl := m.Acl()

esdb/types_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,31 @@ func TestConsistentMetadataSerializationSystemStreamAcl(t *testing.T) {
7474

7575
assert.Equal(t, expected, *meta, "consistency serialization failure")
7676
}
77+
78+
func TestCustomPropertyRetrievalFromStreamMetadata(t *testing.T) {
79+
expected := esdb.StreamMetadata{}
80+
expected.AddCustomProperty("foo", "bar")
81+
82+
foo := expected.CustomProperty("foo")
83+
84+
assert.Equal(t, "bar", foo, "custom property value mismatch")
85+
}
86+
87+
func TestUnknownCustomPropertyRetrievalFromStreamMetadata(t *testing.T) {
88+
expected := esdb.StreamMetadata{}
89+
expected.AddCustomProperty("foo", "bar")
90+
91+
foo := expected.CustomProperty("foes")
92+
93+
assert.Empty(t, foo, "custom property value mismatch")
94+
}
95+
96+
func TestGetAllCustomPropertiesFromStreamMetadata(t *testing.T) {
97+
expected := esdb.StreamMetadata{}
98+
expected.AddCustomProperty("foo", 123)
99+
expected.AddCustomProperty("foes", "baz")
100+
101+
props := expected.CustomProperties()
102+
103+
assert.Equal(t, map[string]interface{}{"foo": 123, "foes": "baz"}, props, "custom properties mismatch")
104+
}

0 commit comments

Comments
 (0)