Skip to content

Commit

Permalink
Merge pull request #335 from OpsLevel/db/fix-sneaky-bug
Browse files Browse the repository at this point in the history
fix error logged when JSONString passed to fmt.Sprintf()
  • Loading branch information
davidbloss authored Dec 13, 2023
2 parents 270a22d + d54dddd commit 9f3881f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Bugfix-20231213-113813.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Bugfix
body: fix error logged when JSONString passed to fmt.Sprintf()
time: 2023-12-13T11:38:13.335444-06:00
12 changes: 6 additions & 6 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,32 @@ func JsonStringAs[T any](data JSONString) (T, error) {
return result, nil
}

func (s JSONString) Bool() bool {
func (s JSONString) AsBool() bool {
value, _ := JsonStringAs[bool](s)
return value
}

func (s JSONString) Int() int {
func (s JSONString) AsInt() int {
value, _ := JsonStringAs[int](s)
return value
}

func (s JSONString) Float64() float64 {
func (s JSONString) AsFloat64() float64 {
value, _ := JsonStringAs[float64](s)
return value
}

func (s JSONString) String() string {
func (s JSONString) AsString() string {
value, _ := JsonStringAs[string](s)
return value
}

func (s JSONString) Array() []any {
func (s JSONString) AsArray() []any {
value, _ := JsonStringAs[[]any](s)
return value
}

func (s JSONString) Map() map[string]any {
func (s JSONString) AsMap() map[string]any {
value, _ := JsonStringAs[map[string]any](s)
return value
}
Expand Down
14 changes: 7 additions & 7 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ func TestUnmarshalJSONString(t *testing.T) {
data4 := []any{"foo", "bar"}
data5 := map[string]any{"foo": "bar"}
// Act
result1 := ol.NewJSONInput(data1).Bool()
result1a := ol.NewJSONInput(data1a).Bool()
result2 := ol.NewJSONInput(data2).Float64()
result2a := ol.NewJSONInput(data2a).Int()
result3 := ol.NewJSONInput(data3).String()
result4 := ol.NewJSONInput(data4).Array()
result5 := ol.NewJSONInput(data5).Map()
result1 := ol.NewJSONInput(data1).AsBool()
result1a := ol.NewJSONInput(data1a).AsBool()
result2 := ol.NewJSONInput(data2).AsFloat64()
result2a := ol.NewJSONInput(data2a).AsInt()
result3 := ol.NewJSONInput(data3).AsString()
result4 := ol.NewJSONInput(data4).AsArray()
result5 := ol.NewJSONInput(data5).AsMap()
_, err := ol.JsonStringAs[float32](ol.NewJSONInput(data1))
// Assert
autopilot.Equals(t, data1, result1)
Expand Down
2 changes: 1 addition & 1 deletion property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestCreatePropertyDefinition(t *testing.T) {
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, expectedPropertyDefinition, *actualPropertyDefinition)
autopilot.Equals(t, ol.JSON(propertyDefinitionInput.Schema.Map()), actualPropertyDefinition.Schema)
autopilot.Equals(t, ol.JSON(propertyDefinitionInput.Schema.AsMap()), actualPropertyDefinition.Schema)
}

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

0 comments on commit 9f3881f

Please sign in to comment.