correct lint findings
This commit is contained in:
@@ -21,7 +21,7 @@ test: mocks tidy fmt vet
|
||||
go tool cover -func=coverage.out
|
||||
|
||||
mocks: mockgen
|
||||
mockgen -destination pkg/mocks/client/mock.go github.com/bakito/adguardhome-sync/pkg/client Client
|
||||
mockgen -package client -destination pkg/mocks/client/mock.go github.com/bakito/adguardhome-sync/pkg/client Client
|
||||
|
||||
release: semver
|
||||
@version=$$(semver); \
|
||||
|
||||
@@ -15,8 +15,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
l = log.GetLogger("client")
|
||||
SetupNeededError = errors.New("setup needed")
|
||||
l = log.GetLogger("client")
|
||||
// ErrSetupNeeded custom error
|
||||
ErrSetupNeeded = errors.New("setup needed")
|
||||
)
|
||||
|
||||
// New create a new client
|
||||
@@ -124,7 +125,7 @@ func (cl *client) doGet(req *resty.Request, url string) error {
|
||||
if resp != nil && resp.StatusCode() == http.StatusFound {
|
||||
loc := resp.Header().Get("Location")
|
||||
if loc == "/install.html" {
|
||||
return SetupNeededError
|
||||
return ErrSetupNeeded
|
||||
}
|
||||
}
|
||||
rl.With("status", resp.StatusCode(), "body", string(resp.Body()), "error", err).Debug("error in do get")
|
||||
|
||||
@@ -107,7 +107,7 @@ bar`)
|
||||
Ω(fs.DNSAddresses[0]).Should(Equal("192.168.1.2"))
|
||||
Ω(fs.Version).Should(Equal("v0.105.2"))
|
||||
})
|
||||
It("should return SetupNeededError", func() {
|
||||
It("should return ErrSetupNeeded", func() {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Location", "/install.html")
|
||||
w.WriteHeader(http.StatusFound)
|
||||
@@ -116,7 +116,7 @@ bar`)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
_, err = cl.Status()
|
||||
Ω(err).Should(HaveOccurred())
|
||||
Ω(err).Should(Equal(client.SetupNeededError))
|
||||
Ω(err).Should(Equal(client.ErrSetupNeeded))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/bakito/adguardhome-sync/pkg/client (interfaces: Client)
|
||||
|
||||
// Package mock_client is a generated GoMock package.
|
||||
package mock_client
|
||||
// Package client is a generated GoMock package.
|
||||
package client
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
// import embed for html page
|
||||
_ "embed"
|
||||
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -237,7 +237,7 @@ func (w *worker) syncTo(l *zap.SugaredLogger, o *origin, replica types.AdGuardIn
|
||||
func (w *worker) statusWithSetup(rl *zap.SugaredLogger, replica types.AdGuardInstance, rc client.Client) (*types.Status, error) {
|
||||
rs, err := rc.Status()
|
||||
if err != nil {
|
||||
if replica.AutoSetup && errors.Is(err, client.SetupNeededError) {
|
||||
if replica.AutoSetup && errors.Is(err, client.ErrSetupNeeded) {
|
||||
if serr := rc.Setup(); serr != nil {
|
||||
rl.With("error", serr).Error("Error setup AdGuardHome")
|
||||
return nil, err
|
||||
|
||||
@@ -3,12 +3,11 @@ package sync
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/bakito/adguardhome-sync/pkg/client"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
mc "github.com/bakito/adguardhome-sync/pkg/mocks/client"
|
||||
"github.com/bakito/adguardhome-sync/pkg/client"
|
||||
clientmock "github.com/bakito/adguardhome-sync/pkg/mocks/client"
|
||||
"github.com/bakito/adguardhome-sync/pkg/types"
|
||||
gm "github.com/golang/mock/gomock"
|
||||
"github.com/google/uuid"
|
||||
@@ -17,14 +16,14 @@ import (
|
||||
var _ = Describe("Sync", func() {
|
||||
var (
|
||||
mockCtrl *gm.Controller
|
||||
cl *mc.MockClient
|
||||
cl *clientmock.MockClient
|
||||
w *worker
|
||||
te error
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
mockCtrl = gm.NewController(GinkgoT())
|
||||
cl = mc.NewMockClient(mockCtrl)
|
||||
cl = clientmock.NewMockClient(mockCtrl)
|
||||
w = &worker{
|
||||
createClient: func(instance types.AdGuardInstance) (client.Client, error) {
|
||||
return cl, nil
|
||||
@@ -284,7 +283,7 @@ var _ = Describe("Sync", func() {
|
||||
Ω(st).Should(Equal(status))
|
||||
})
|
||||
It("should runs setup before getting replica status", func() {
|
||||
cl.EXPECT().Status().Return(nil, client.SetupNeededError)
|
||||
cl.EXPECT().Status().Return(nil, client.ErrSetupNeeded)
|
||||
cl.EXPECT().Setup()
|
||||
cl.EXPECT().Status().Return(status, nil)
|
||||
st, err := w.statusWithSetup(l, inst, cl)
|
||||
@@ -292,7 +291,7 @@ var _ = Describe("Sync", func() {
|
||||
Ω(st).Should(Equal(status))
|
||||
})
|
||||
It("should fail on setup", func() {
|
||||
cl.EXPECT().Status().Return(nil, client.SetupNeededError)
|
||||
cl.EXPECT().Status().Return(nil, client.ErrSetupNeeded)
|
||||
cl.EXPECT().Setup().Return(te)
|
||||
st, err := w.statusWithSetup(l, inst, cl)
|
||||
Ω(err).Should(HaveOccurred())
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// DHCPServerConfig dhcp server config
|
||||
type DHCPServerConfig struct {
|
||||
V4 *V4ServerConfJSON `json:"v4"`
|
||||
V6 *V6ServerConfJSON `json:"v6"`
|
||||
@@ -23,6 +24,7 @@ func (c *DHCPServerConfig) Equals(o *DHCPServerConfig) bool {
|
||||
return string(a) == string(b)
|
||||
}
|
||||
|
||||
// V4ServerConfJSON v4 server conf
|
||||
type V4ServerConfJSON struct {
|
||||
GatewayIP net.IP `json:"gateway_ip"`
|
||||
SubnetMask net.IP `json:"subnet_mask"`
|
||||
@@ -31,12 +33,14 @@ type V4ServerConfJSON struct {
|
||||
LeaseDuration uint32 `json:"lease_duration"`
|
||||
}
|
||||
|
||||
// V6ServerConfJSON v6 server conf
|
||||
type V6ServerConfJSON struct {
|
||||
RangeStart net.IP `json:"range_start"`
|
||||
RangeEnd net.IP `json:"range_end"`
|
||||
LeaseDuration uint32 `json:"lease_duration"`
|
||||
}
|
||||
|
||||
// Leases slice of leases type
|
||||
type Leases []Lease
|
||||
|
||||
// Merge the leases
|
||||
|
||||
+2
-13
@@ -6,19 +6,7 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// https://ha.bakito.net:3000/control/dns_config
|
||||
// {"bootstrap_dns":["1.1.1.1:53"],"upstream_mode":"parallel","upstream_dns":["https://dns10.quad9.net/dns-query"]}
|
||||
// {"bootstrap_dns":["1.1.1.1:53"],"upstream_mode":"","upstream_dns":["https://dns10.quad9.net/dns-query"]}
|
||||
// {"bootstrap_dns":["1.1.1.1:53"],"upstream_mode":"fastest_addr","upstream_dns":["https://dns10.quad9.net/dns-query"]}
|
||||
|
||||
// {"ratelimit":20,"blocking_mode":"default","blocking_ipv4":"0.0.0.0","blocking_ipv6":"::","edns_cs_enabled":true,"disable_ipv6":false,"dnssec_enabled":false}
|
||||
// {"cache_size":4194304,"cache_ttl_max":0,"cache_ttl_min":0}
|
||||
|
||||
// https://ha.bakito.net:3000/control/access/set
|
||||
// {"allowed_clients":["2.2.2.2"],"disallowed_clients":["1.1.1.1"],"blocked_hosts":["version.bind","id.server","hostname.bind"]}
|
||||
// https://ha.bakito.net:3000/control/access/list
|
||||
// {"allowed_clients":[],"disallowed_clients":[],"blocked_hosts":["version.bind","id.server","hostname.bind"]}
|
||||
|
||||
// DNSConfig dns config
|
||||
type DNSConfig struct {
|
||||
Upstreams []string `json:"upstream_dns,omitempty"`
|
||||
UpstreamsFile string `json:"upstream_dns_file"`
|
||||
@@ -57,6 +45,7 @@ func (c *DNSConfig) Sort() {
|
||||
sort.Strings(c.LocalPTRUpstreams)
|
||||
}
|
||||
|
||||
// AccessList access list
|
||||
type AccessList struct {
|
||||
AllowedClients []string `json:"allowed_clients"`
|
||||
DisallowedClients []string `json:"disallowed_clients"`
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultAPIPath default api path
|
||||
DefaultAPIPath = "/control"
|
||||
)
|
||||
|
||||
@@ -57,6 +58,7 @@ func (cfg *Config) UniqueReplicas() []AdGuardInstance {
|
||||
return r
|
||||
}
|
||||
|
||||
// WithBeta return true if the given beta feature is enabled
|
||||
func (cfg *Config) WithBeta(name string) bool {
|
||||
doOnce.Do(func() {
|
||||
cfg.enabledBeta = make(map[string]bool)
|
||||
|
||||
Reference in New Issue
Block a user