Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CustomProperty and CustomProperties method to StreamMetadata #179

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions esdb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ func (m *StreamMetadata) StreamAcl() *Acl {
return nil
}

// CustomProperty The custom property value for the given key.
func (m *StreamMetadata) CustomProperty(key string) interface{} {
return m.customProperties[key]
}

// CustomProperties returns all custom properties.
func (m *StreamMetadata) CustomProperties() map[string]interface{} {
return m.customProperties
}

// IsUserStreamAcl Checks if the ACL is set to users default.
func (m *StreamMetadata) IsUserStreamAcl() bool {
acl := m.Acl()
Expand Down
28 changes: 28 additions & 0 deletions esdb/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,31 @@ func TestConsistentMetadataSerializationSystemStreamAcl(t *testing.T) {

assert.Equal(t, expected, *meta, "consistency serialization failure")
}

func TestCustomPropertyRetrievalFromStreamMetadata(t *testing.T) {
expected := esdb.StreamMetadata{}
expected.AddCustomProperty("foo", "bar")

foo := expected.CustomProperty("foo")

assert.Equal(t, "bar", foo, "custom property value mismatch")
}

func TestUnknownCustomPropertyRetrievalFromStreamMetadata(t *testing.T) {
expected := esdb.StreamMetadata{}
expected.AddCustomProperty("foo", "bar")

foo := expected.CustomProperty("foes")

assert.Empty(t, foo, "custom property value mismatch")
}

func TestGetAllCustomPropertiesFromStreamMetadata(t *testing.T) {
expected := esdb.StreamMetadata{}
expected.AddCustomProperty("foo", 123)
expected.AddCustomProperty("foes", "baz")

props := expected.CustomProperties()

assert.Equal(t, map[string]interface{}{"foo": 123, "foes": "baz"}, props, "custom properties mismatch")
}
Loading