1
0
Fork 0

feat: new linting system.

This commit is contained in:
Ludovic Fernandez 2019-03-04 16:40:05 +01:00 committed by Traefiker Bot
parent fb617044e0
commit ebded2cbc0
24 changed files with 129 additions and 256 deletions

View file

@ -103,8 +103,10 @@ func (a *ACME) AddRoutes(router *mux.Router) {
}
tokenValue := a.challengeHTTPProvider.getTokenValue(token, domain)
if len(tokenValue) > 0 {
rw.WriteHeader(http.StatusOK)
rw.Write(tokenValue)
_, err := rw.Write(tokenValue)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
}
return
}
}
@ -131,7 +133,11 @@ func (a *ACME) CreateClusterConfig(leadership *cluster.Leadership, tlsConfig *tl
listener := func(object cluster.Object) error {
account := object.(*Account)
account.Init()
err := account.Init()
if err != nil {
return err
}
if !leadership.IsLeader() {
a.client, err = a.buildACMEClient(account)
if err != nil {
@ -187,7 +193,11 @@ func (a *ACME) leadershipListener(elected bool) error {
}
account := object.(*Account)
account.Init()
err = account.Init()
if err != nil {
return err
}
// Reset Account values if caServer changed, thus registration URI can be updated
if account != nil && account.Registration != nil && !isAccountMatchingCaServer(account.Registration.URI, a.CAServer) {
log.Info("Account URI does not match the current CAServer. The account will be reset")

View file

@ -15,6 +15,7 @@ import (
"github.com/containous/traefik/tls/generate"
"github.com/containous/traefik/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDomainsSet(t *testing.T) {
@ -58,7 +59,7 @@ func TestDomainsSet(t *testing.T) {
t.Parallel()
domains := types.Domains{}
domains.Set(test.input)
_ = domains.Set(test.input)
assert.Exactly(t, test.expected, domains)
})
}
@ -110,7 +111,7 @@ func TestDomainsSetAppend(t *testing.T) {
for _, test := range testCases {
t.Run(test.input, func(t *testing.T) {
domains.Set(test.input)
_ = domains.Set(test.input)
assert.Exactly(t, test.expected, domains)
})
}
@ -237,7 +238,9 @@ func TestRemoveDuplicates(t *testing.T) {
},
},
}
domainsCertificates.Init()
err := domainsCertificates.Init()
require.NoError(t, err)
if len(domainsCertificates.Certs) != 2 {
t.Errorf("Expected domainsCertificates length %d %+v\nGot %+v", 2, domainsCertificates.Certs, len(domainsCertificates.Certs))
@ -790,7 +793,8 @@ func TestRemoveEmptyCertificates(t *testing.T) {
t.Parallel()
a := &Account{DomainsCertificate: *test.dc}
a.Init()
err := a.Init()
require.NoError(t, err)
assert.Equal(t, len(test.expectedDc.Certs), len(a.DomainsCertificate.Certs))
sort.Sort(&a.DomainsCertificate)

View file

@ -88,9 +88,7 @@ func (c *challengeHTTPProvider) CleanUp(domain, token, keyAuth string) error {
account := object.(*Account)
if _, ok := account.HTTPChallenge[token]; ok {
if _, domainOk := account.HTTPChallenge[token][domain]; domainOk {
delete(account.HTTPChallenge[token], domain)
}
delete(account.HTTPChallenge[token], domain)
if len(account.HTTPChallenge[token]) == 0 {
delete(account.HTTPChallenge, token)
}

View file

@ -37,7 +37,11 @@ func (c *challengeTLSProvider) getCertificate(domain string) (cert *tls.Certific
return nil, false
}
account.Init()
err := account.Init()
if err != nil {
log.Errorf("Unable to init ACME Account: %v", err)
return nil, false
}
var result *tls.Certificate
operation := func() error {
@ -58,7 +62,7 @@ func (c *challengeTLSProvider) getCertificate(domain string) (cert *tls.Certific
ebo := backoff.NewExponentialBackOff()
ebo.MaxElapsedTime = 60 * time.Second
err := backoff.RetryNotify(safe.OperationWithRecover(operation), ebo, notify)
err = backoff.RetryNotify(safe.OperationWithRecover(operation), ebo, notify)
if err != nil {
log.Errorf("Error getting cert: %v", err)
return nil, false

View file

@ -21,7 +21,8 @@ func TestGet(t *testing.T) {
fileContent, err := ioutil.ReadFile(acmeFile)
assert.NoError(t, err)
tmpFile.Write(fileContent)
_, err = tmpFile.Write(fileContent)
assert.NoError(t, err)
localStore := NewLocalStore(tmpFile.Name())
account, err := localStore.Get()