123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920 |
- package mapping
- import (
- "reflect"
- "strings"
- "testing"
- "github.com/stretchr/testify/assert"
- )
- func TestUnmarshalYamlBytes(t *testing.T) {
- var c struct {
- Name string
- }
- content := []byte(`Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Name)
- }
- func TestUnmarshalYamlBytesOptional(t *testing.T) {
- var c struct {
- Name string
- Age int `json:",optional"`
- }
- content := []byte(`Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Name)
- }
- func TestUnmarshalYamlBytesOptionalDefault(t *testing.T) {
- var c struct {
- Name string
- Age int `json:",optional,default=1"`
- }
- content := []byte(`Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Name)
- assert.Equal(t, 1, c.Age)
- }
- func TestUnmarshalYamlBytesDefaultOptional(t *testing.T) {
- var c struct {
- Name string
- Age int `json:",default=1,optional"`
- }
- content := []byte(`Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Name)
- assert.Equal(t, 1, c.Age)
- }
- func TestUnmarshalYamlBytesDefault(t *testing.T) {
- var c struct {
- Name string `json:",default=liao"`
- }
- content := []byte(`{}`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Name)
- }
- func TestUnmarshalYamlBytesBool(t *testing.T) {
- var c struct {
- Great bool
- }
- content := []byte(`Great: true`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.True(t, c.Great)
- }
- func TestUnmarshalYamlBytesInt(t *testing.T) {
- var c struct {
- Age int
- }
- content := []byte(`Age: 1`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, c.Age)
- }
- func TestUnmarshalYamlBytesUint(t *testing.T) {
- var c struct {
- Age uint
- }
- content := []byte(`Age: 1`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, uint(1), c.Age)
- }
- func TestUnmarshalYamlBytesFloat(t *testing.T) {
- var c struct {
- Age float32
- }
- content := []byte(`Age: 1.5`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, float32(1.5), c.Age)
- }
- func TestUnmarshalYamlBytesMustInOptional(t *testing.T) {
- var c struct {
- Inner struct {
- There string
- Must string
- Optional string `json:",optional"`
- } `json:",optional"`
- }
- content := []byte(`{}`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesMustInOptionalMissedPart(t *testing.T) {
- var c struct {
- Inner struct {
- There string
- Must string
- Optional string `json:",optional"`
- } `json:",optional"`
- }
- content := []byte(`Inner:
- There: sure`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesMustInOptionalOnlyOptionalFilled(t *testing.T) {
- var c struct {
- Inner struct {
- There string
- Must string
- Optional string `json:",optional"`
- } `json:",optional"`
- }
- content := []byte(`Inner:
- Optional: sure`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesPartial(t *testing.T) {
- var c struct {
- Name string
- Age float32
- }
- content := []byte(`Age: 1.5`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesStruct(t *testing.T) {
- var c struct {
- Inner struct {
- Name string
- }
- }
- content := []byte(`Inner:
- Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Inner.Name)
- }
- func TestUnmarshalYamlBytesStructOptional(t *testing.T) {
- var c struct {
- Inner struct {
- Name string
- Age int `json:",optional"`
- }
- }
- content := []byte(`Inner:
- Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Inner.Name)
- }
- func TestUnmarshalYamlBytesStructPtr(t *testing.T) {
- var c struct {
- Inner *struct {
- Name string
- }
- }
- content := []byte(`Inner:
- Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Inner.Name)
- }
- func TestUnmarshalYamlBytesStructPtrOptional(t *testing.T) {
- var c struct {
- Inner *struct {
- Name string
- Age int `json:",optional"`
- }
- }
- content := []byte(`Inner:
- Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesStructPtrDefault(t *testing.T) {
- var c struct {
- Inner *struct {
- Name string
- Age int `json:",default=4"`
- }
- }
- content := []byte(`Inner:
- Name: liao`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "liao", c.Inner.Name)
- assert.Equal(t, 4, c.Inner.Age)
- }
- func TestUnmarshalYamlBytesSliceString(t *testing.T) {
- var c struct {
- Names []string
- }
- content := []byte(`Names:
- - liao
- - chaoxin`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- want := []string{"liao", "chaoxin"}
- if !reflect.DeepEqual(c.Names, want) {
- t.Fatalf("want %q, got %q", c.Names, want)
- }
- }
- func TestUnmarshalYamlBytesSliceStringOptional(t *testing.T) {
- var c struct {
- Names []string
- Age []int `json:",optional"`
- }
- content := []byte(`Names:
- - liao
- - chaoxin`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- want := []string{"liao", "chaoxin"}
- if !reflect.DeepEqual(c.Names, want) {
- t.Fatalf("want %q, got %q", c.Names, want)
- }
- }
- func TestUnmarshalYamlBytesSliceStruct(t *testing.T) {
- var c struct {
- People []struct {
- Name string
- Age int
- }
- }
- content := []byte(`People:
- - Name: liao
- Age: 1
- - Name: chaoxin
- Age: 2`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- want := []struct {
- Name string
- Age int
- }{
- {"liao", 1},
- {"chaoxin", 2},
- }
- if !reflect.DeepEqual(c.People, want) {
- t.Fatalf("want %q, got %q", c.People, want)
- }
- }
- func TestUnmarshalYamlBytesSliceStructOptional(t *testing.T) {
- var c struct {
- People []struct {
- Name string
- Age int
- Emails []string `json:",optional"`
- }
- }
- content := []byte(`People:
- - Name: liao
- Age: 1
- - Name: chaoxin
- Age: 2`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- want := []struct {
- Name string
- Age int
- Emails []string `json:",optional"`
- }{
- {"liao", 1, nil},
- {"chaoxin", 2, nil},
- }
- if !reflect.DeepEqual(c.People, want) {
- t.Fatalf("want %q, got %q", c.People, want)
- }
- }
- func TestUnmarshalYamlBytesSliceStructPtr(t *testing.T) {
- var c struct {
- People []*struct {
- Name string
- Age int
- }
- }
- content := []byte(`People:
- - Name: liao
- Age: 1
- - Name: chaoxin
- Age: 2`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- want := []*struct {
- Name string
- Age int
- }{
- {"liao", 1},
- {"chaoxin", 2},
- }
- if !reflect.DeepEqual(c.People, want) {
- t.Fatalf("want %v, got %v", c.People, want)
- }
- }
- func TestUnmarshalYamlBytesSliceStructPtrOptional(t *testing.T) {
- var c struct {
- People []*struct {
- Name string
- Age int
- Emails []string `json:",optional"`
- }
- }
- content := []byte(`People:
- - Name: liao
- Age: 1
- - Name: chaoxin
- Age: 2`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- want := []*struct {
- Name string
- Age int
- Emails []string `json:",optional"`
- }{
- {"liao", 1, nil},
- {"chaoxin", 2, nil},
- }
- if !reflect.DeepEqual(c.People, want) {
- t.Fatalf("want %v, got %v", c.People, want)
- }
- }
- func TestUnmarshalYamlBytesSliceStructPtrPartial(t *testing.T) {
- var c struct {
- People []*struct {
- Name string
- Age int
- Email string
- }
- }
- content := []byte(`People:
- - Name: liao
- Age: 1
- - Name: chaoxin
- Age: 2`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesSliceStructPtrDefault(t *testing.T) {
- var c struct {
- People []*struct {
- Name string
- Age int
- Email string `json:",default=chaoxin@liao.com"`
- }
- }
- content := []byte(`People:
- - Name: liao
- Age: 1
- - Name: chaoxin
- Age: 2`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- want := []*struct {
- Name string
- Age int
- Email string
- }{
- {"liao", 1, "chaoxin@liao.com"},
- {"chaoxin", 2, "chaoxin@liao.com"},
- }
- for i := range c.People {
- actual := c.People[i]
- expect := want[i]
- assert.Equal(t, expect.Age, actual.Age)
- assert.Equal(t, expect.Email, actual.Email)
- assert.Equal(t, expect.Name, actual.Name)
- }
- }
- func TestUnmarshalYamlBytesSliceStringPartial(t *testing.T) {
- var c struct {
- Names []string
- Age int
- }
- content := []byte(`Age: 1`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesSliceStructPartial(t *testing.T) {
- var c struct {
- Group string
- People []struct {
- Name string
- Age int
- }
- }
- content := []byte(`Group: chaoxin`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesInnerAnonymousPartial(t *testing.T) {
- type (
- Deep struct {
- A string
- B string `json:",optional"`
- }
- Inner struct {
- Deep
- InnerV string `json:",optional"`
- }
- )
- var c struct {
- Value Inner `json:",optional"`
- }
- content := []byte(`Value:
- InnerV: chaoxin`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesStructPartial(t *testing.T) {
- var c struct {
- Group string
- Person struct {
- Name string
- Age int
- }
- }
- content := []byte(`Group: chaoxin`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesEmptyMap(t *testing.T) {
- var c struct {
- Persons map[string]int `json:",optional"`
- }
- content := []byte(`{}`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Empty(t, c.Persons)
- }
- func TestUnmarshalYamlBytesMap(t *testing.T) {
- var c struct {
- Persons map[string]int
- }
- content := []byte(`Persons:
- first: 1
- second: 2`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 2, len(c.Persons))
- assert.Equal(t, 1, c.Persons["first"])
- assert.Equal(t, 2, c.Persons["second"])
- }
- func TestUnmarshalYamlBytesMapStruct(t *testing.T) {
- var c struct {
- Persons map[string]struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first:
- Id: 1
- name: kevin`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Equal(t, 1, c.Persons["first"].Id)
- assert.Equal(t, "kevin", c.Persons["first"].Name)
- }
- func TestUnmarshalYamlBytesMapStructPtr(t *testing.T) {
- var c struct {
- Persons map[string]*struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first:
- Id: 1
- name: kevin`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Equal(t, 1, c.Persons["first"].Id)
- assert.Equal(t, "kevin", c.Persons["first"].Name)
- }
- func TestUnmarshalYamlBytesMapStructMissingPartial(t *testing.T) {
- var c struct {
- Persons map[string]*struct {
- Id int
- Name string
- }
- }
- content := []byte(`Persons:
- first:
- Id: 1`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesMapStructOptional(t *testing.T) {
- var c struct {
- Persons map[string]*struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first:
- Id: 1`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Equal(t, 1, c.Persons["first"].Id)
- }
- func TestUnmarshalYamlBytesMapStructSlice(t *testing.T) {
- var c struct {
- Persons map[string][]struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first:
- - Id: 1
- name: kevin`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Equal(t, 1, c.Persons["first"][0].Id)
- assert.Equal(t, "kevin", c.Persons["first"][0].Name)
- }
- func TestUnmarshalYamlBytesMapEmptyStructSlice(t *testing.T) {
- var c struct {
- Persons map[string][]struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first: []`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Empty(t, c.Persons["first"])
- }
- func TestUnmarshalYamlBytesMapStructPtrSlice(t *testing.T) {
- var c struct {
- Persons map[string][]*struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first:
- - Id: 1
- name: kevin`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Equal(t, 1, c.Persons["first"][0].Id)
- assert.Equal(t, "kevin", c.Persons["first"][0].Name)
- }
- func TestUnmarshalYamlBytesMapEmptyStructPtrSlice(t *testing.T) {
- var c struct {
- Persons map[string][]*struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first: []`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Empty(t, c.Persons["first"])
- }
- func TestUnmarshalYamlBytesMapStructPtrSliceMissingPartial(t *testing.T) {
- var c struct {
- Persons map[string][]*struct {
- Id int
- Name string
- }
- }
- content := []byte(`Persons:
- first:
- - Id: 1`)
- assert.NotNil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlBytesMapStructPtrSliceOptional(t *testing.T) {
- var c struct {
- Persons map[string][]*struct {
- Id int
- Name string `json:"name,optional"`
- }
- }
- content := []byte(`Persons:
- first:
- - Id: 1`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, 1, len(c.Persons))
- assert.Equal(t, 1, c.Persons["first"][0].Id)
- }
- func TestUnmarshalYamlStructOptional(t *testing.T) {
- var c struct {
- Name string
- Etcd struct {
- Hosts []string
- Key string
- } `json:",optional"`
- }
- content := []byte(`Name: kevin`)
- err := UnmarshalYamlBytes(content, &c)
- assert.Nil(t, err)
- assert.Equal(t, "kevin", c.Name)
- }
- func TestUnmarshalYamlStructLowerCase(t *testing.T) {
- var c struct {
- Name string
- Etcd struct {
- Key string
- } `json:"etcd"`
- }
- content := []byte(`Name: kevin
- etcd:
- Key: the key`)
- err := UnmarshalYamlBytes(content, &c)
- assert.Nil(t, err)
- assert.Equal(t, "kevin", c.Name)
- assert.Equal(t, "the key", c.Etcd.Key)
- }
- func TestUnmarshalYamlWithStructAllOptionalWithEmpty(t *testing.T) {
- var c struct {
- Inner struct {
- Optional string `json:",optional"`
- }
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlWithStructAllOptionalPtr(t *testing.T) {
- var c struct {
- Inner *struct {
- Optional string `json:",optional"`
- }
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlWithStructOptional(t *testing.T) {
- type Inner struct {
- Must string
- }
- var c struct {
- In Inner `json:",optional"`
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Equal(t, "", c.In.Must)
- }
- func TestUnmarshalYamlWithStructPtrOptional(t *testing.T) {
- type Inner struct {
- Must string
- }
- var c struct {
- In *Inner `json:",optional"`
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Nil(t, c.In)
- }
- func TestUnmarshalYamlWithStructAllOptionalAnonymous(t *testing.T) {
- type Inner struct {
- Optional string `json:",optional"`
- }
- var c struct {
- Inner
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlWithStructAllOptionalAnonymousPtr(t *testing.T) {
- type Inner struct {
- Optional string `json:",optional"`
- }
- var c struct {
- *Inner
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- }
- func TestUnmarshalYamlWithStructAllOptionalProvoidedAnonymous(t *testing.T) {
- type Inner struct {
- Optional string `json:",optional"`
- }
- var c struct {
- Inner
- Else string
- }
- content := []byte(`Else: sure
- Optional: optional`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Equal(t, "optional", c.Optional)
- }
- func TestUnmarshalYamlWithStructAllOptionalProvoidedAnonymousPtr(t *testing.T) {
- type Inner struct {
- Optional string `json:",optional"`
- }
- var c struct {
- *Inner
- Else string
- }
- content := []byte(`Else: sure
- Optional: optional`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Equal(t, "optional", c.Optional)
- }
- func TestUnmarshalYamlWithStructAnonymous(t *testing.T) {
- type Inner struct {
- Must string
- }
- var c struct {
- Inner
- Else string
- }
- content := []byte(`Else: sure
- Must: must`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Equal(t, "must", c.Must)
- }
- func TestUnmarshalYamlWithStructAnonymousPtr(t *testing.T) {
- type Inner struct {
- Must string
- }
- var c struct {
- *Inner
- Else string
- }
- content := []byte(`Else: sure
- Must: must`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Equal(t, "must", c.Must)
- }
- func TestUnmarshalYamlWithStructAnonymousOptional(t *testing.T) {
- type Inner struct {
- Must string
- }
- var c struct {
- Inner `json:",optional"`
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Equal(t, "", c.Must)
- }
- func TestUnmarshalYamlWithStructPtrAnonymousOptional(t *testing.T) {
- type Inner struct {
- Must string
- }
- var c struct {
- *Inner `json:",optional"`
- Else string
- }
- content := []byte(`Else: sure`)
- assert.Nil(t, UnmarshalYamlBytes(content, &c))
- assert.Equal(t, "sure", c.Else)
- assert.Nil(t, c.Inner)
- }
- func TestUnmarshalYamlWithZeroValues(t *testing.T) {
- type inner struct {
- False bool `json:"negative"`
- Int int `json:"int"`
- String string `json:"string"`
- }
- content := []byte(`negative: false
- int: 0
- string: ""`)
- var in inner
- ast := assert.New(t)
- ast.Nil(UnmarshalYamlBytes(content, &in))
- ast.False(in.False)
- ast.Equal(0, in.Int)
- ast.Equal("", in.String)
- }
- func TestUnmarshalYamlBytesError(t *testing.T) {
- payload := `abcd:
- - cdef`
- var v struct {
- Any []string `json:"abcd"`
- }
- err := UnmarshalYamlBytes([]byte(payload), &v)
- assert.Nil(t, err)
- assert.Equal(t, 1, len(v.Any))
- assert.Equal(t, "cdef", v.Any[0])
- }
- func TestUnmarshalYamlReaderError(t *testing.T) {
- payload := `abcd: cdef`
- reader := strings.NewReader(payload)
- var v struct {
- Any string
- }
- err := UnmarshalYamlReader(reader, &v)
- assert.NotNil(t, err)
- }
|