Skip to content

Commit

Permalink
Expose namespace data (#2804)
Browse files Browse the repository at this point in the history
* Expose namespace data
  • Loading branch information
yux0 committed May 5, 2022
1 parent ae84776 commit ddb29dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ func (ns *Namespace) ReplicationPolicy() ReplicationPolicy {
return ReplicationPolicyOneCluster
}

func (ns *Namespace) GetCustomData(key string) string {
if ns.info.Data == nil {
return ""
}
return ns.info.Data[key]
}

// Len return length
func (t Namespaces) Len() int {
return len(t)
Expand Down
11 changes: 11 additions & 0 deletions common/namespace/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
namespacepb "go.temporal.io/api/namespace/v1"
Expand Down Expand Up @@ -131,3 +133,12 @@ func Test_GetRetentionDays(t *testing.T) {
})
}
}

func TestNamespace_GetCustomData(t *testing.T) {
base := base(t)
ns := base.Clone(namespace.WithData("foo", "bar"))
data := ns.GetCustomData("foo")
assert.Equal(t, "bar", data)
data2 := ns.GetCustomData("fake")
assert.Equal(t, "", data2)
}

0 comments on commit ddb29dc

Please sign in to comment.