Skip to content

Commit

Permalink
feat: add method to access flag metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
robclemons committed Mar 6, 2024
1 parent f87920e commit 855728b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/experiment/local/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ func (c *Client) FlagsV2() (string, error) {
return flagsString, nil
}

// FlagMetadata returns a copy of the flag's metadata. If the flag is not found then nil is returned.
func (c *Client) FlagMetadata(flagKey string) map[string]interface{} {
c.flagsMutex.RLock()
f := c.flags[flagKey]
c.flagsMutex.RUnlock()
if f == nil {
return nil
}

metadata := make(map[string]interface{})
for k, v := range f.Metadata {
metadata[k] = v
}

return metadata
}

func (c *Client) doFlagsV2() (map[string]*evaluation.Flag, error) {
client := &http.Client{}
endpoint, err := url.Parse("https://api.lab.amplitude.com/")
Expand Down
14 changes: 14 additions & 0 deletions pkg/experiment/local/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,17 @@ func TestEvaluateV2UnknownFlagKey(t *testing.T) {
t.Fatalf("Unexpected variant %v", variant)
}
}

func TestFlagMetadataUnknownFlagKey(t *testing.T) {
md := client.FlagMetadata("does-not-exist")
if md != nil {
t.Fatalf("Unexpected metadata %v", md)
}
}

func TestFlagMetadataLocalFlagKey(t *testing.T) {
md := client.FlagMetadata("sdk-local-evaluation-ci-test")
if md["evaluationMode"] != "local" {
t.Fatalf("Unexpected metadata %v", md)
}
}

0 comments on commit 855728b

Please sign in to comment.