Skip to content

Commit

Permalink
Merge pull request #9 from microsoft/feature/go-enums
Browse files Browse the repository at this point in the history
- adds support for enum responses
  • Loading branch information
baywet authored May 27, 2022
2 parents 2bd7167 + 4c54112 commit 1a517c9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.4.0] - 2022-05-26

### Changed

- Updated reference to kiota abstractions for enum response support.

## [0.3.0] - 2022-05-19

### Changed
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ go 1.18

require (
github.com/google/uuid v1.3.0
github.com/microsoft/kiota-abstractions-go v0.7.0
github.com/microsoft/kiota-abstractions-go v0.8.0
github.com/stretchr/testify v1.7.1
)

require (
github.com/cjlapao/common-go v0.0.19 // indirect
github.com/cjlapao/common-go v0.0.20 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
13 changes: 4 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
github.com/cjlapao/common-go v0.0.19 h1:dhPllblgZwHn92u8wNleLDCg6+T2rjV57H8eyz82tbQ=
github.com/cjlapao/common-go v0.0.19/go.mod h1:EVLEXIxsBHblPMrhJYOvL4yBCcBj7IYDdW88VlfxpPM=
github.com/cjlapao/common-go v0.0.20 h1:AIZBtuxwJPXFqyxFOlvVDWZgbsuTSquZEUw4KMx8pNg=
github.com/cjlapao/common-go v0.0.20/go.mod h1:EVLEXIxsBHblPMrhJYOvL4yBCcBj7IYDdW88VlfxpPM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/microsoft/kiota-abstractions-go v0.6.0 h1:e/mJM8+xidaTxOvuVLdY0uB/3GFHxyZB43vhjmxAuME=
github.com/microsoft/kiota-abstractions-go v0.6.0/go.mod h1:fL1Ni2uXdlRPGicO4Ut0aOLmkpunYuAAJwRBLgDhzw4=
github.com/microsoft/kiota-abstractions-go v0.7.0 h1:/yPcUaiTOUvq4stz8qrPi9UWljnCGBcksRYS2BZpUBk=
github.com/microsoft/kiota-abstractions-go v0.7.0/go.mod h1:fL1Ni2uXdlRPGicO4Ut0aOLmkpunYuAAJwRBLgDhzw4=
github.com/microsoft/kiota-abstractions-go v0.8.0 h1:mtilyDlfM9EUe4blByCmQh/iO7S0176zHd+oxr7rh20=
github.com/microsoft/kiota-abstractions-go v0.8.0/go.mod h1:uWv0yQ4lYJtK9NIK5RAmw/LeIMUbIG0asu36v4yjyjY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
4 changes: 2 additions & 2 deletions text_parse_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (n *TextParseNode) GetCollectionOfPrimitiveValues(targetType string) ([]int
}

// GetCollectionOfEnumValues returns the collection of Enum values from the node.
func (n *TextParseNode) GetCollectionOfEnumValues(parser func(string) (interface{}, error)) ([]interface{}, error) {
func (n *TextParseNode) GetCollectionOfEnumValues(parser absser.EnumFactory) ([]interface{}, error) {
return nil, NoStructuredDataError
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func (n *TextParseNode) GetUUIDValue() (*uuid.UUID, error) {
}

// GetEnumValue returns a Enum value from the nodes.
func (n *TextParseNode) GetEnumValue(parser func(string) (interface{}, error)) (interface{}, error) {
func (n *TextParseNode) GetEnumValue(parser absser.EnumFactory) (interface{}, error) {
if parser == nil {
return nil, errors.New("parser is nil")
}
Expand Down
13 changes: 13 additions & 0 deletions text_parse_node_factory_text.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package textserialization

import (
testing "testing"

absser "github.com/microsoft/kiota-abstractions-go/serialization"
assert "github.com/stretchr/testify/assert"
)

func TestTextParseFactoryNodeHonoursInterface(t *testing.T) {
instance := NewTextParseNodeFactory()
assert.Implements(t, (*absser.ParseNodeFactory)(nil), instance)
}
20 changes: 15 additions & 5 deletions text_parse_node_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package textserialization

import (
assert "github.com/stretchr/testify/assert"
testing "testing"

absser "github.com/microsoft/kiota-abstractions-go/serialization"
assert "github.com/stretchr/testify/assert"
)

func TestTree(t *testing.T) {
Expand All @@ -15,9 +17,17 @@ func TestTree(t *testing.T) {
someProp, err := parseNode.GetChildNode("someProp")
assert.NotNil(t, err)
assert.Nil(t, someProp)

stringValue, err := parseNode.GetStringValue()
assert.Nil(t, err)
assert.NotNil(t, stringValue)
assert.Equal(t, "stringValue", *stringValue)
assert.Nil(t, err)
assert.NotNil(t, stringValue)
assert.Equal(t, "stringValue", *stringValue)
}

func TestTextParseNodeHonoursInterface(t *testing.T) {
source := "\"stringValue\""
sourceArray := []byte(source)
instance, err := NewTextParseNode(sourceArray)
assert.Nil(t, err)
assert.Implements(t, (*absser.ParseNode)(nil), instance)
}
13 changes: 13 additions & 0 deletions text_serialization_writer_factory_text.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package textserialization

import (
testing "testing"

absser "github.com/microsoft/kiota-abstractions-go/serialization"
assert "github.com/stretchr/testify/assert"
)

func TestSerializationWriterFactoryHonoursInterface(t *testing.T) {
instance := NewTextSerializationWriterFactory()
assert.Implements(t, (*absser.SerializationWriterFactory)(nil), instance)
}
9 changes: 8 additions & 1 deletion text_serialization_writer_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package textserialization

import (
assert "github.com/stretchr/testify/assert"
"testing"

absser "github.com/microsoft/kiota-abstractions-go/serialization"
assert "github.com/stretchr/testify/assert"
)

func TestItDoesntWriteAnythingForAdditionalData(t *testing.T) {
serializer := NewTextSerializationWriter()
err := serializer.WriteAdditionalData(nil)
assert.NotNil(t, err)
}

func TestSerializationWriterHonoursInterface(t *testing.T) {
instance := NewTextSerializationWriter()
assert.Implements(t, (*absser.SerializationWriter)(nil), instance)
}

0 comments on commit 1a517c9

Please sign in to comment.