William Cheng 14d41310b9
[Go] replace go generator with go-experimental generator (#7337)
* replace go with go-experimental

* update samples

* extends with abstract go class

* rearrange

* remove deprecated

* minor fix

* remove go deprecated samples

* update pom, clean up samples

* mark generator as deprecated
2020-09-04 09:56:42 +08:00

44 lines
1.3 KiB
Go

package main
import (
"encoding/json"
"testing"
sw "./go-petstore"
"github.com/stretchr/testify/assert"
)
func TestBanana(t *testing.T) {
assert := assert.New(t)
lengthCm := float32(2.3)
lengthCm2 := float32(2.4)
newBanana := (sw.Banana{LengthCm: &lengthCm})
newBanana.LengthCm = &lengthCm2
assert.Equal(newBanana.LengthCm, &lengthCm2, "Banana LengthCm should be equal")
// test additioanl properties
jsonBanana := `{"fruits":["apple","peach"],"lengthCm":3.1}`
jsonMap := make(map[string]interface{})
json.Unmarshal([]byte(jsonBanana), &jsonMap)
newBanana2 := (sw.Banana{})
lengthCm3 := float32(3.1)
json.Unmarshal([]byte(jsonBanana), &newBanana2)
assert.Equal(newBanana2.LengthCm, &lengthCm3, "Banana2 LengthCm should be equal")
assert.Equal(newBanana2.AdditionalProperties["fruits"], jsonMap["fruits"], "Banana2 AdditonalProperties should be equal")
newBanana2Json, _ := json.Marshal(newBanana2)
assert.Equal(string(newBanana2Json), jsonBanana, "Banana2 JSON string should be equal")
}
func TestDog(t *testing.T) {
assert := assert.New(t)
newDog := (sw.Dog{})
jsonDog := `{"breed":"Shepherd","className":"dog","color":"white"}`
json.Unmarshal([]byte(jsonDog), &newDog)
breedString := "Shepherd"
//assert.Nil(newDog)
assert.Equal(*newDog.Breed, breedString, "Breed should be `Shepherd`")
}