Skip to content

Commit

Permalink
feat: adds initial support for complex attributes
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Attributes interface has been removed and AttributeSet interface has been modified

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jan 18, 2023
1 parent 83bef51 commit 50955bf
Show file tree
Hide file tree
Showing 36 changed files with 731 additions and 587 deletions.
144 changes: 0 additions & 144 deletions attributes/attributes.go

This file was deleted.

125 changes: 0 additions & 125 deletions attributes/attributes_test.go

This file was deleted.

20 changes: 5 additions & 15 deletions attributes/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,18 @@ import (
"github.com/emporous/emporous-go/model"
)

type boolAttribute struct {
key string
value bool
}

var _ model.Attribute = boolAttribute{}
type boolAttribute bool

// NewBool returns a boolean attribute.
func NewBool(key string, value bool) model.Attribute {
return boolAttribute{key: key, value: value}
func NewBool(value bool) model.AttributeValue {
return boolAttribute(value)
}

// Kind returns the kind for the attribute.
func (a boolAttribute) Kind() model.Kind {
return model.KindBool
}

// Key return the attribute key.
func (a boolAttribute) Key() string {
return a.key
}

// IsNull returns whether the value is null.
func (a boolAttribute) IsNull() bool {
return false
Expand All @@ -34,7 +24,7 @@ func (a boolAttribute) IsNull() bool {
// AsBool returns the value as a boolean and errors if that is not
// the underlying type.
func (a boolAttribute) AsBool() (bool, error) {
return a.value, nil
return bool(a), nil
}

// AsString returns the value as a string and errors if that is not
Expand Down Expand Up @@ -69,5 +59,5 @@ func (a boolAttribute) AsObject() (map[string]model.AttributeValue, error) {

// AsAny returns the value as an interface.
func (a boolAttribute) AsAny() interface{} {
return a.value
return bool(a)
}
12 changes: 6 additions & 6 deletions attributes/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ import (
)

func TestBoolAttribute_Kind(t *testing.T) {
test := NewBool("test", true)
test := NewBool(true)
require.Equal(t, model.KindBool, test.Kind())
}

func TestBoolAttribute_AsBool(t *testing.T) {
test := NewBool("test", true)
test := NewBool(true)
b, err := test.AsBool()
require.NoError(t, err)
require.Equal(t, true, b)
}

func TestBoolAttribute_AsFloat(t *testing.T) {
test := NewBool("test", false)
test := NewBool(false)
b, err := test.AsFloat()
require.ErrorIs(t, ErrWrongKind, err)
require.Equal(t, float64(0), b)
}

func TestBoolAttribute_AsInt(t *testing.T) {
test := NewBool("test", false)
test := NewBool(false)
b, err := test.AsInt()
require.ErrorIs(t, ErrWrongKind, err)
require.Equal(t, int64(0), b)
}

func TestBoolAttribute_AsString(t *testing.T) {
test := NewBool("test", false)
test := NewBool(false)
b, err := test.AsString()
require.ErrorIs(t, ErrWrongKind, err)
require.Equal(t, "", b)
}

func TestBoolAttribute_IsNull(t *testing.T) {
test := NewBool("test", false)
test := NewBool(false)
require.False(t, test.IsNull())
}
Loading

0 comments on commit 50955bf

Please sign in to comment.