Skip to content

Commit

Permalink
Add yaml test with empty arrays (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Nov 4, 2021
1 parent 8b60707 commit 2f40c1f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aconfigyaml/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/cristalhq/aconfig/aconfigyaml
go 1.15

require (
github.com/cristalhq/aconfig v0.16.1
github.com/cristalhq/aconfig v0.16.8
gopkg.in/yaml.v2 v2.3.0
)
4 changes: 2 additions & 2 deletions aconfigyaml/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cristalhq/aconfig v0.16.1 h1:P3noQOujaPU5Of8E9fA1YYU3s/HUoPCIhpKkEgIQtfc=
github.com/cristalhq/aconfig v0.16.1/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/cristalhq/aconfig v0.16.8 h1:lg8i0XHgfhvsnjNM5q/ou6jIHDRXlbBybjRP9t2fWuw=
github.com/cristalhq/aconfig v0.16.8/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
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.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
Expand Down
3 changes: 3 additions & 0 deletions aconfigyaml/res.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources_a:

resources_b:
28 changes: 28 additions & 0 deletions aconfigyaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ func TestYAML(t *testing.T) {
}
}

func TestLoadResources(t *testing.T) {
type ResourceA struct {
Field string `yaml:"field"`
}
type ResourceB struct {
Field int `yaml:"field"`
}
type TestConfig struct {
ResourcesA []ResourceA `yaml:"resources_a"`
ResourcesB []ResourceB `yaml:"resources_b"`
}

var cfg TestConfig

resourcesLoader := aconfig.LoaderFor(&cfg,
aconfig.Config{
SkipFlags: true,
Files: []string{"res.yaml"},
FailOnFileNotFound: true,
FileDecoders: map[string]aconfig.FileDecoder{
".yaml": aconfigyaml.New(),
},
})
if err := resourcesLoader.Load(); err != nil {
t.Errorf("failed to load resources configurations [err=%s]", err)
}
}

func createTestFile(t *testing.T) string {
t.Helper()
dir := t.TempDir()
Expand Down

0 comments on commit 2f40c1f

Please sign in to comment.