Skip to content

Commit

Permalink
fix(audit): include default_variant into flag audit payload (#3472)
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Dmytrenko <[email protected]>
  • Loading branch information
erka authored Sep 17, 2024
1 parent ebca332 commit eeb329e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/server/audit/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ import (
// the different sinks.

type Flag struct {
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
NamespaceKey string `json:"namespace_key"`
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
NamespaceKey string `json:"namespace_key"`
DefaultVariant string `json:"default_variant,omitempty"`
}

func NewFlag(f *flipt.Flag) *Flag {
return &Flag{
af := &Flag{
Key: f.Key,
Name: f.Name,
Description: f.Description,
Enabled: f.Enabled,
NamespaceKey: f.NamespaceKey,
}
if f.DefaultVariant != nil {
af.DefaultVariant = f.DefaultVariant.Key
}
return af
}

type Variant struct {
Expand Down
21 changes: 21 additions & 0 deletions internal/server/audit/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,39 @@ import (
)

func TestFlag(t *testing.T) {
f := &flipt.Flag{
Key: "flipt",
Name: "flipt",
NamespaceKey: "flipt",
Enabled: false,
DefaultVariant: nil,
}
nf := NewFlag(f)

assert.Equal(t, nf.Enabled, f.Enabled)
assert.Equal(t, nf.Key, f.Key)
assert.Equal(t, nf.Name, f.Name)
assert.Equal(t, nf.NamespaceKey, f.NamespaceKey)
}

func TestFlagWithDefaultVariant(t *testing.T) {
f := &flipt.Flag{
Key: "flipt",
Name: "flipt",
NamespaceKey: "flipt",
Enabled: false,
DefaultVariant: &flipt.Variant{
Key: "default-variant",
},
}
nf := NewFlag(f)

assert.Equal(t, nf.Enabled, f.Enabled)
assert.Equal(t, nf.Key, f.Key)
assert.Equal(t, nf.Name, f.Name)
assert.Equal(t, nf.NamespaceKey, f.NamespaceKey)
assert.Equal(t, "default-variant", nf.DefaultVariant)

}

func TestVariant(t *testing.T) {
Expand Down

0 comments on commit eeb329e

Please sign in to comment.