mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-04 17:06:49 +00:00
Add more unit tests
This commit is contained in:
@ -9,6 +9,12 @@ import (
|
||||
"github.com/rotisserie/eris"
|
||||
)
|
||||
|
||||
var (
|
||||
certificateGetByID = certificate.GetByID
|
||||
upstreamGetByID = upstream.GetByID
|
||||
nginxtemplateGetByID = nginxtemplate.GetByID
|
||||
)
|
||||
|
||||
// ValidateHost will check if associated objects exist and other checks
|
||||
// will return a nil error if things are OK
|
||||
func ValidateHost(h host.Model) error {
|
||||
@ -16,14 +22,14 @@ func ValidateHost(h host.Model) error {
|
||||
// Check certificate exists and is valid
|
||||
// This will not determine if the certificate is Ready to use,
|
||||
// as this validation only cares that the row exists.
|
||||
if _, cErr := certificate.GetByID(h.CertificateID.Uint); cErr != nil {
|
||||
if _, cErr := certificateGetByID(h.CertificateID.Uint); cErr != nil {
|
||||
return eris.Wrapf(cErr, "Certificate #%d does not exist", h.CertificateID.Uint)
|
||||
}
|
||||
}
|
||||
|
||||
if h.UpstreamID.Uint > 0 {
|
||||
// Check upstream exists
|
||||
if _, uErr := upstream.GetByID(h.UpstreamID.Uint); uErr != nil {
|
||||
if _, uErr := upstreamGetByID(h.UpstreamID.Uint); uErr != nil {
|
||||
return eris.Wrapf(uErr, "Upstream #%d does not exist", h.UpstreamID.Uint)
|
||||
}
|
||||
}
|
||||
@ -37,7 +43,7 @@ func ValidateHost(h host.Model) error {
|
||||
}
|
||||
|
||||
// Check the nginx template exists and has the same type.
|
||||
nginxTemplate, tErr := nginxtemplate.GetByID(h.NginxTemplateID)
|
||||
nginxTemplate, tErr := nginxtemplateGetByID(h.NginxTemplateID)
|
||||
if tErr != nil {
|
||||
return eris.Wrapf(tErr, "Host Template #%d does not exist", h.NginxTemplateID)
|
||||
}
|
||||
|
Reference in New Issue
Block a user