-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds KindInt to Attribute Kinds and updates README.md with new …
…attribute query instructions Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
- Loading branch information
Showing
36 changed files
with
573 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package attributes | ||
|
||
import "github.com/uor-framework/uor-client-go/model" | ||
|
||
type floatAttribute struct { | ||
key string | ||
value float64 | ||
} | ||
|
||
var _ model.Attribute = floatAttribute{} | ||
|
||
// NewFloat returns a number attribute. | ||
func NewFloat(key string, value float64) model.Attribute { | ||
return floatAttribute{key: key, value: value} | ||
} | ||
|
||
// Kind returns the kind for the attribute. | ||
func (a floatAttribute) Kind() model.Kind { | ||
return model.KindFloat | ||
} | ||
|
||
// Key return the attribute key. | ||
func (a floatAttribute) Key() string { | ||
return a.key | ||
} | ||
|
||
// IsNull returns whether the value is null. | ||
func (a floatAttribute) IsNull() bool { | ||
return false | ||
} | ||
|
||
// AsBool returns the value as a boolean errors if that is not | ||
// the underlying type. | ||
func (a floatAttribute) AsBool() (bool, error) { | ||
return false, ErrWrongKind | ||
} | ||
|
||
// AsString returns the value as a string errors if that is not | ||
// the underlying type. | ||
func (a floatAttribute) AsString() (string, error) { | ||
return "", ErrWrongKind | ||
} | ||
|
||
// AsFloat returns the value as a number value and errors if that is not | ||
// the underlying type. | ||
func (a floatAttribute) AsFloat() (float64, error) { | ||
return a.value, nil | ||
} | ||
|
||
// AsInt returns the value as a number value and errors if that is not | ||
// the underlying type. | ||
func (a floatAttribute) AsInt() (int, error) { | ||
return 0, ErrWrongKind | ||
} | ||
|
||
// AsAny returns the value as an interface. | ||
func (a floatAttribute) AsAny() interface{} { | ||
return a.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package attributes | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"github.com/uor-framework/uor-client-go/model" | ||
"testing" | ||
) | ||
|
||
func TestFloatAttribute_Kind(t *testing.T) { | ||
test := NewFloat("test", 1) | ||
require.Equal(t, model.KindFloat, test.Kind()) | ||
} | ||
|
||
func TestFloatAttribute_AsBool(t *testing.T) { | ||
test := NewFloat("test", 1) | ||
n, err := test.AsBool() | ||
require.ErrorIs(t, ErrWrongKind, err) | ||
require.Equal(t, false, n) | ||
} | ||
|
||
func TestFloatAttribute_AsFloat(t *testing.T) { | ||
test := NewFloat("test", 1) | ||
n, err := test.AsFloat() | ||
require.NoError(t, err) | ||
require.Equal(t, float64(1), n) | ||
} | ||
|
||
func TestFloatAttribute_AsInt(t *testing.T) { | ||
test := NewFloat("test", 1) | ||
n, err := test.AsInt() | ||
require.ErrorIs(t, ErrWrongKind, err) | ||
require.Equal(t, 0, n) | ||
} | ||
|
||
func TestFloatAttribute_AsString(t *testing.T) { | ||
test := NewFloat("test", 1) | ||
n, err := test.AsString() | ||
require.ErrorIs(t, ErrWrongKind, err) | ||
require.Equal(t, "", n) | ||
} | ||
|
||
func TestFloatAttribute_IsNull(t *testing.T) { | ||
test := NewFloat("test", 1.0) | ||
require.False(t, test.IsNull()) | ||
} |
Oops, something went wrong.