help people figure out why their syslog url is wrong more better (#1242)

closes #1240
This commit is contained in:
Reed Allman
2018-09-26 11:56:14 -07:00
committed by GitHub
parent 1855ebf2ce
commit 911c7d993e
2 changed files with 5 additions and 6 deletions

View File

@@ -86,17 +86,16 @@ func (a *App) Validate() error {
if a.SyslogURL != nil && *a.SyslogURL != "" {
url, err := url.Parse(strings.TrimSpace(*a.SyslogURL))
fail := err != nil
if !fail {
if err == nil {
// See: https://docs.docker.com/config/containers/logging/syslog/#options
switch url.Scheme {
case "udp", "tcp", "unix", "unixgram", "tcp+tls":
default:
fail = true
err = fmt.Errorf("invalid scheme, only [tcp, udp, unix, unixgram, tcp+tls] are supported")
}
}
if fail {
return ErrInvalidSyslog(fmt.Sprintf(`invalid syslog url: "%v"`, *a.SyslogURL))
if err != nil { // not else if for a reason...
return ErrInvalidSyslog(fmt.Sprintf(`invalid syslog url: "%v" %v`, *a.SyslogURL, err))
}
}
return nil

View File

@@ -56,7 +56,7 @@ func TestAppCreate(t *testing.T) {
{datastore.NewMock(), logs.NewMock(), "/v2/apps", `{ "name": "app", "annotations" : { "":"val" }}`, http.StatusBadRequest, models.ErrInvalidAnnotationKey},
{datastore.NewMock(), logs.NewMock(), "/v2/apps", `{"name": "app", "annotations" : { "key":"" }}`, http.StatusBadRequest, models.ErrInvalidAnnotationValue},
{datastore.NewMock(), logs.NewMock(), "/v2/apps", `{ "name": "app", "syslog_url":"yo"}`, http.StatusBadRequest, errors.New(`invalid syslog url: "yo"`)},
{datastore.NewMock(), logs.NewMock(), "/v2/apps", `{"name": "app", "syslog_url":"yo://sup.com:1"}`, http.StatusBadRequest, errors.New(`invalid syslog url: "yo://sup.com:1"`)},
{datastore.NewMock(), logs.NewMock(), "/v2/apps", `{"name": "app", "syslog_url":"yo://sup.com:1"}`, http.StatusBadRequest, errors.New(`invalid syslog url: "yo://sup.com:1" invalid scheme, only [tcp, udp, unix, unixgram, tcp+tls] are supported`)},
// success
{datastore.NewMock(), logs.NewMock(), "/v2/apps", `{ "name": "teste" }`, http.StatusOK, nil},
{datastore.NewMock(), logs.NewMock(), "/v2/apps", `{ "name": "teste" , "annotations": {"k1":"v1", "k2":[]}}`, http.StatusOK, nil},