lint: multiple warns

This commit is contained in:
Umputun
2021-04-03 01:00:09 -05:00
parent a316070eb6
commit 79f0514294
7 changed files with 18 additions and 17 deletions

View File

@@ -34,8 +34,10 @@ type Provider interface {
ID() ProviderID
}
// ProviderID holds provider identifier to emulate enum of them
type ProviderID string
// enum of all provider ids
const (
PIDocker ProviderID = "docker"
PIStatic ProviderID = "static"

View File

@@ -118,6 +118,7 @@ func TestService_Match(t *testing.T) {
}
for i, tt := range tbl {
tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
res, ok := svc.Match(tt.server, tt.src)
assert.Equal(t, tt.ok, ok)

View File

@@ -48,14 +48,15 @@ var (
func (d *Docker) Events(ctx context.Context) (res <-chan struct{}) {
eventsCh := make(chan struct{})
go func() {
// loop over to recover from failed events call
for {
err := d.events(ctx, d.DockerClient, eventsCh)
err := d.events(ctx, d.DockerClient, eventsCh) // publish events to eventsCh
if err == context.Canceled || err == context.DeadlineExceeded {
close(eventsCh)
return
}
log.Printf("[WARN] docker events listener failed, restarted, %v", err)
time.Sleep(100 * time.Millisecond)
time.Sleep(100 * time.Millisecond) // prevent busy loop on restart event listener
}
}()
return eventsCh

View File

@@ -23,6 +23,7 @@ func TestStatic_List(t *testing.T) {
}
for i, tt := range tbl {
tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
s := Static{Rules: []string{tt.rule}}
res, err := s.List()

View File

@@ -61,16 +61,6 @@ var opts struct {
Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"`
}
// SSLGroup defines options group for server ssl params
type SSLGroup struct {
Type string `long:"type" env:"TYPE" description:"ssl (auto) support" choice:"none" choice:"static" choice:"auto" default:"none"` //nolint
Port int `long:"port" env:"PORT" description:"port number for https server" default:"8443"`
Cert string `long:"cert" env:"CERT" description:"path to cert.pem file"`
Key string `long:"key" env:"KEY" description:"path to key.pem file"`
ACMELocation string `long:"acme-location" env:"ACME_LOCATION" description:"dir where certificates will be stored by autocert manager" default:"./var/acme"`
ACMEEmail string `long:"acme-email" env:"ACME_EMAIL" description:"admin email for certificate notifications"`
}
var revision = "unknown"
func main() {
@@ -101,8 +91,8 @@ func main() {
svc := discovery.NewService(providers)
go func() {
if err := svc.Run(context.Background()); err != nil {
log.Fatalf("[ERROR] discovery failed, %v", err)
if e := svc.Run(context.Background()); e != nil {
log.Fatalf("[ERROR] discovery failed, %v", e)
}
}()
@@ -121,6 +111,7 @@ func main() {
AssetsWebRoot: opts.Assets.WebRoot,
GzEnabled: opts.GzipEnabled,
SSLConfig: sslConfig,
ProxyHeaders: opts.ProxyHeaders,
}
if err := px.Run(context.Background()); err != nil {
log.Fatalf("[ERROR] proxy server failed, %v", err)

View File

@@ -37,12 +37,14 @@ func TestHttp_Do(t *testing.T) {
}})
go func() {
svc.Run(context.Background())
err := svc.Run(context.Background())
assert.Equal(t, context.DeadlineExceeded, err)
}()
h.Matcher = svc
go func() {
h.Run(ctx)
err := h.Run(ctx)
assert.Equal(t, context.DeadlineExceeded, err)
}()
time.Sleep(10 * time.Millisecond)
@@ -51,6 +53,7 @@ func TestHttp_Do(t *testing.T) {
{
resp, err := client.Get("http://127.0.0.1:" + strconv.Itoa(port) + "/api/something")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
t.Logf("%+v", resp.Header)
@@ -64,6 +67,7 @@ func TestHttp_Do(t *testing.T) {
{
resp, err := client.Get("http://localhost:" + strconv.Itoa(port) + "/api/something")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
t.Logf("%+v", resp.Header)
@@ -77,6 +81,7 @@ func TestHttp_Do(t *testing.T) {
{
resp, err := client.Get("http://127.0.0.1:" + strconv.Itoa(port) + "/bad/something")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusBadGateway, resp.StatusCode)
}

View File

@@ -28,7 +28,7 @@ func TestSSL_Redirect(t *testing.T) {
// allow self-signed certificate
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint
},
}