mirror of https://github.com/status-im/consul.git
Added unit tests for bad meta values
This commit is contained in:
parent
d2ab3deacf
commit
2f5e67534d
|
@ -999,7 +999,7 @@ func (b *Builder) serviceVal(v *ServiceDefinition) *structs.ServiceDefinition {
|
||||||
|
|
||||||
meta := make(map[string]string)
|
meta := make(map[string]string)
|
||||||
if err := structs.ValidateMetadata(v.Meta, false); err != nil {
|
if err := structs.ValidateMetadata(v.Meta, false); err != nil {
|
||||||
b.err = multierror.Append(fmt.Errorf("invalid meta for service %v: %v", v.Name, err))
|
b.err = multierror.Append(fmt.Errorf("invalid meta for service %s: %v", *v.Name, err))
|
||||||
} else {
|
} else {
|
||||||
meta = v.Meta
|
meta = v.Meta
|
||||||
}
|
}
|
||||||
|
|
|
@ -1939,6 +1939,32 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
rt.DataDir = dataDir
|
rt.DataDir = dataDir
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "service with wrong meta: too long",
|
||||||
|
args: []string{
|
||||||
|
`-data-dir=` + dataDir,
|
||||||
|
},
|
||||||
|
json: []string{
|
||||||
|
`{ "service": { "name": "a", "port": 80, "meta": { "a": "` + randomString(520) + `" } } }`,
|
||||||
|
},
|
||||||
|
hcl: []string{
|
||||||
|
`service = { name = "a" port = 80, meta={a="` + randomString(520) + `"} }`,
|
||||||
|
},
|
||||||
|
err: `Value is too long`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "service with wrong meta: too many meta",
|
||||||
|
args: []string{
|
||||||
|
`-data-dir=` + dataDir,
|
||||||
|
},
|
||||||
|
json: []string{
|
||||||
|
`{ "service": { "name": "a", "port": 80, "meta": { ` + metaPairs(70, "json") + `} } }`,
|
||||||
|
},
|
||||||
|
hcl: []string{
|
||||||
|
`service = { name = "a" port = 80 meta={` + metaPairs(70, "hcl") + `} }`,
|
||||||
|
},
|
||||||
|
err: `invalid meta for service a: Node metadata cannot contain more than 64 key`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "translated keys",
|
desc: "translated keys",
|
||||||
args: []string{
|
args: []string{
|
||||||
|
|
Loading…
Reference in New Issue