Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit c588d9e

Browse files
committed
Replace metadata array of tables with just table
- Makes metadata TOML table. - Allows metadata table in "dependencies" and "overrides".
1 parent e518855 commit c588d9e

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

manifest.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bytes"
99
"fmt"
1010
"io"
11+
"reflect"
1112
"sort"
1213

1314
"github.com/golang/dep/gps"
@@ -54,24 +55,26 @@ func validateManifest(s string) ([]error, error) {
5455
for prop, val := range manifest {
5556
switch prop {
5657
case "metadata":
57-
// Invalid if type assertion fails. Not a TOML array of tables.
58-
// This check is enough for map validation because any non-key-value
59-
// pair inside array of tables becomes an invalid TOML and parser
60-
// would fail.
61-
if _, ok := val.([]interface{}); !ok {
62-
errs = append(errs, errors.New("metadata should be a TOML array of tables"))
58+
// Check if metadata is of Map type
59+
if reflect.TypeOf(val).Kind() != reflect.Map {
60+
errs = append(errs, errors.New("metadata should be a TOML table"))
6361
}
6462
case "dependencies", "overrides":
6563
// Invalid if type assertion fails. Not a TOML array of tables.
6664
if rawProj, ok := val.([]interface{}); ok {
6765
// Iterate through each array of tables
6866
for _, v := range rawProj {
6967
// Check the individual field's key to be valid
70-
for key, _ := range v.(map[string]interface{}) {
68+
for key, value := range v.(map[string]interface{}) {
7169
// Check if the key is valid
7270
switch key {
7371
case "name", "branch", "revision", "version", "source":
7472
// valid key
73+
case "metadata":
74+
// Check if metadata is of Map type
75+
if reflect.TypeOf(value).Kind() != reflect.Map {
76+
errs = append(errs, fmt.Errorf("metadata in %q should be a TOML table", prop))
77+
}
7578
default:
7679
// unknown/invalid key
7780
errs = append(errs, fmt.Errorf("Invalid key %q in %q", key, prop))

manifest_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestValidateManifest(t *testing.T) {
135135
},
136136
{
137137
tomlString: `
138-
[[metadata]]
138+
[metadata]
139139
authors = "foo"
140140
version = "1.0.0"
141141
`,
@@ -166,7 +166,7 @@ func TestValidateManifest(t *testing.T) {
166166
[[dependencies]]
167167
name = "github.com/foo/bar"
168168
`,
169-
want: []error{errors.New("metadata should be a TOML array of tables")},
169+
want: []error{errors.New("metadata should be a TOML table")},
170170
},
171171
{
172172
tomlString: `
@@ -184,6 +184,7 @@ func TestValidateManifest(t *testing.T) {
184184
name = "github.com/foo/bar"
185185
location = "some-value"
186186
link = "some-other-value"
187+
metadata = "foo"
187188
188189
[[overrides]]
189190
nick = "foo"
@@ -192,8 +193,19 @@ func TestValidateManifest(t *testing.T) {
192193
errors.New("Invalid key \"location\" in \"dependencies\""),
193194
errors.New("Invalid key \"link\" in \"dependencies\""),
194195
errors.New("Invalid key \"nick\" in \"overrides\""),
196+
errors.New("metadata in \"dependencies\" should be a TOML table"),
195197
},
196198
},
199+
{
200+
tomlString: `
201+
[[dependencies]]
202+
name = "github.com/foo/bar"
203+
204+
[dependencies.metadata]
205+
color = "blue"
206+
`,
207+
want: []error{},
208+
},
197209
}
198210

199211
// constains for error

0 commit comments

Comments
 (0)