diff --git a/pkg/backends/alb/client.go b/pkg/backends/alb/client.go index 3a49513b4..623e22ca1 100644 --- a/pkg/backends/alb/client.go +++ b/pkg/backends/alb/client.go @@ -17,7 +17,6 @@ package alb import ( - "errors" "fmt" "net/http" "strings" @@ -29,6 +28,7 @@ import ( "github.com/trickstercache/trickster/v2/pkg/backends/providers" "github.com/trickstercache/trickster/v2/pkg/backends/providers/registration/types" "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/errors" "github.com/trickstercache/trickster/v2/pkg/proxy/methods" "github.com/trickstercache/trickster/v2/pkg/proxy/paths/matching" po "github.com/trickstercache/trickster/v2/pkg/proxy/paths/options" @@ -157,7 +157,7 @@ func (c *Client) ValidatePool(clients backends.Backends) error { // validate and map out the pool configuration func (c *Client) ValidateAndStartPool(clients backends.Backends, hcs healthcheck.StatusLookup) error { if c.Configuration() == nil || c.Configuration().ALBOptions == nil { - return errors.New("invalid options") + return errors.ErrInvalidOptions } o := c.Configuration().ALBOptions @@ -172,7 +172,7 @@ func (c *Client) ValidateAndStartPool(clients backends.Backends, hcs healthcheck if !ok { return fmt.Errorf("invalid pool member name [%s] in backend [%s]", n, c.Name()) } - hc, _ := hcs[n] + hc := hcs[n] targets = append(targets, pool.NewTarget(tc.Router(), hc)) } c.pool = pool.New(m, targets, o.HealthyFloor) diff --git a/pkg/backends/alb/client_test.go b/pkg/backends/alb/client_test.go index 97c37209f..61c2ec6b9 100644 --- a/pkg/backends/alb/client_test.go +++ b/pkg/backends/alb/client_test.go @@ -46,25 +46,25 @@ func TestHandlers(t *testing.T) { } a.MechanismName = "fgr" - cl, err = NewClient("test", o, nil, nil, nil, nil) + _, err = NewClient("test", o, nil, nil, nil, nil) if err != nil { t.Error(err) } a.MechanismName = "nlm" - cl, err = NewClient("test", o, nil, nil, nil, nil) + _, err = NewClient("test", o, nil, nil, nil, nil) if err != nil { t.Error(err) } a.MechanismName = "tsm" - cl, err = NewClient("test", o, nil, nil, nil, types.Lookup{"prometheus": prometheus.NewClient}) + _, err = NewClient("test", o, nil, nil, nil, types.Lookup{"prometheus": prometheus.NewClient}) if err != nil { t.Error(err) } a.MechanismName = "rr" - cl, err = NewClient("test", o, nil, nil, nil, nil) + _, err = NewClient("test", o, nil, nil, nil, nil) if err != nil { t.Error(err) } diff --git a/pkg/backends/irondb/health_test.go b/pkg/backends/irondb/health_test.go index 2255363f3..56a2656e8 100644 --- a/pkg/backends/irondb/health_test.go +++ b/pkg/backends/irondb/health_test.go @@ -29,9 +29,7 @@ func TestDefaultHealthCheckConfig(t *testing.T) { dho := c.DefaultHealthCheckConfig() if dho == nil { t.Error("expected non-nil result") - } - - if dho.Path != "" { + } else if dho.Path != "" { t.Error("expected / for path", dho.Path) } diff --git a/pkg/backends/irondb/irondb_test.go b/pkg/backends/irondb/irondb_test.go index db561f73c..491d07098 100644 --- a/pkg/backends/irondb/irondb_test.go +++ b/pkg/backends/irondb/irondb_test.go @@ -20,7 +20,6 @@ import ( "testing" "github.com/trickstercache/trickster/v2/pkg/backends" - "github.com/trickstercache/trickster/v2/pkg/backends/irondb/model" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" "github.com/trickstercache/trickster/v2/pkg/config" @@ -48,8 +47,6 @@ func TestIRONdbClientInterfacing(t *testing.T) { } } -var testModeler = model.NewModeler() - func TestNewClient(t *testing.T) { conf, _, err := config.Load("trickster", "test", []string{"-origin-url", "http://example.com", "-provider", "TEST_CLIENT"}) diff --git a/pkg/backends/irondb/url.go b/pkg/backends/irondb/url.go index 81edd1fc9..04f403237 100644 --- a/pkg/backends/irondb/url.go +++ b/pkg/backends/irondb/url.go @@ -17,10 +17,10 @@ package irondb import ( - "errors" "fmt" "net/http" + tkerr "github.com/trickstercache/trickster/v2/pkg/errors" terr "github.com/trickstercache/trickster/v2/pkg/proxy/errors" "github.com/trickstercache/trickster/v2/pkg/proxy/request" "github.com/trickstercache/trickster/v2/pkg/timeseries" @@ -45,7 +45,7 @@ func (c *Client) FastForwardRequest(r *http.Request) (*http.Request, error) { rsc := request.GetResources(r) if rsc == nil || rsc.PathConfig == nil { - return nil, errors.New("missing path config") + return nil, tkerr.ErrMissingPathconfig } switch rsc.PathConfig.HandlerName { @@ -68,7 +68,7 @@ func (c *Client) ParseTimeRangeQuery( rsc := request.GetResources(r) if rsc == nil || rsc.PathConfig == nil { - return nil, nil, false, errors.New("missing path config") + return nil, nil, false, tkerr.ErrMissingPathconfig } var trq *timeseries.TimeRangeQuery diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 35fa03671..fafc47b8a 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -20,3 +20,9 @@ import "errors" // ErrNilWriter is an error for a nil writer when a non-nil writer was expected var ErrNilWriter = errors.New("nil writer") + +// ErrInvalidOptions is an error for when a configuration is invalid +var ErrInvalidOptions = errors.New("invalid options") + +// ErrMissingPathconfig is an error for when a configuration is missing a path value +var ErrMissingPathconfig = errors.New("missing path config")