Skip to content

Commit

Permalink
fix(lint): lint config updates and fixes (#63)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <[email protected]>
  • Loading branch information
hairyhenderson authored May 30, 2024
1 parent abf97e7 commit 3241cfb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 177 deletions.
9 changes: 2 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
linters-settings:
govet:
check-shadowing: true
enable:
- fieldalignment
golint:
min-confidence: 0
enable-all: true
gocyclo:
min-complexity: 10
goconst:
Expand All @@ -13,7 +9,6 @@ linters-settings:
lll:
line-length: 140
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand Down Expand Up @@ -41,7 +36,7 @@ linters:
- gofumpt
- goheader
- goimports
- gomnd
# - mnd
- gomodguard
- goprintffuncname
- gosec
Expand Down
17 changes: 12 additions & 5 deletions admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import (
func TestCMReboot(t *testing.T) {
body := `{"errCode":"000","errMsg":""}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)

d := testCableModem(srv)
ctx := ContextWithDebugLogger(context.Background(), t)
Expand All @@ -25,3 +21,14 @@ func TestCMReboot(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, &Error{Code: "000"}, o)
}

func staticResponseServer(t *testing.T, body string) *httptest.Server {
t.Helper()

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(body))
}))
t.Cleanup(srv.Close)

return srv
}
46 changes: 8 additions & 38 deletions cm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"fmt"
"net"
"net/http"
"net/http/httptest"
"testing"
"time"

Expand All @@ -19,11 +17,7 @@ func TestVersion(t *testing.T) {
"HwVersion":"1A","ApiVersion":"1.11","SoftwareVersion":"7.1.1.2.2b9"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

v, err := d.CMVersion(context.Background())
Expand All @@ -49,11 +43,7 @@ func TestCMDocsisProvision(t *testing.T) {
"networkAccess":"Permitted","trafficStatus":"Enable"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.CMDocsisProvision(context.Background())
Expand Down Expand Up @@ -85,9 +75,7 @@ func TestCMDsInfo(t *testing.T) {
{"signalStrength":false,"snr":true}
]}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))
srv := staticResponseServer(t, body)
defer srv.Close()

d := testCableModem(srv)
Expand Down Expand Up @@ -127,9 +115,7 @@ func TestCMUsInfo(t *testing.T) {
{"portId":"8","frequency":"0","modulationType":"QAM_NONE",
"signalStrength":"-","bandwidth":"1600000","channelId":"0"}]}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))
srv := staticResponseServer(t, body)
defer srv.Close()

d := testCableModem(srv)
Expand Down Expand Up @@ -166,11 +152,7 @@ func TestCMSysInfo(t *testing.T) {
"lease":"D: 6 H: 09 M: 25 S: 55","Configname":"bac110000106749be82df7e0",
"DsDataRate":"1040000000","UsDataRate":"31200000","macAddr":"74:9b:DE:AD:BE:EF"}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.CMSysInfo(context.Background())
Expand Down Expand Up @@ -201,11 +183,7 @@ func TestCMDsOFDM(t *testing.T) {
"plclock":"YES","ncplock":"YES","mdc1lock":"YES","plcpower":" 0.799999"}
]}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.CMDsOfdm(context.Background())
Expand Down Expand Up @@ -235,11 +213,7 @@ func TestCMUsOFDM(t *testing.T) {
"repPower":" 0.0000","repPower1_6":" 0.0000",
"fftVal":" 2K"}]}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.CMUsOfdm(context.Background())
Expand All @@ -264,11 +238,7 @@ func TestCMLog(t *testing.T) {
"event":"%s"}
]}`, msg1, msg2)

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

t1, err := time.Parse(time.RFC3339, "2020-11-15T03:57:38Z")
Expand Down
4 changes: 2 additions & 2 deletions hitron.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func New(host, username, password string) (*CableModem, error) {
client := &http.Client{
Jar: jar,
// Ignore redirects
CheckRedirect: func(req *http.Request, via []*http.Request) error {
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
Transport: &debugTransport{http.DefaultTransport},
Expand Down Expand Up @@ -121,7 +121,7 @@ func debugLoggerFromContext(ctx context.Context) debugLogger {
}
}

return debugLoggerFunc(func(f string, args ...interface{}) {})
return debugLoggerFunc(func(_ string, _ ...interface{}) {})
}

func (c *CableModem) getJSON(ctx context.Context, path string, o interface{}) error {
Expand Down
1 change: 1 addition & 0 deletions login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestLogout(t *testing.T) {
w.Header().Set("Set-Cookie", cookie.String())
w.WriteHeader(http.StatusOK)
}

n++
}))

Expand Down
32 changes: 5 additions & 27 deletions misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package hitron
import (
"context"
"net"
"net/http"
"net/http/httptest"
"testing"
"time"

Expand All @@ -17,11 +15,7 @@ func TestTime(t *testing.T) {
"daylightOnOff":"ON","daylightTime":"0"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.Time(context.Background())
Expand All @@ -47,11 +41,7 @@ func TestDNS(t *testing.T) {
"proxyName1":"foo","proxyName2":"bar"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

ctx := ContextWithDebugLogger(context.Background(), t)
Expand All @@ -78,11 +68,7 @@ func TestDDNS(t *testing.T) {
"ddnsHostnames":"foo.example.com","ddnsUpdateInterval":"604800"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

ctx := ContextWithDebugLogger(context.Background(), t)
Expand Down Expand Up @@ -114,11 +100,7 @@ func TestHosts(t *testing.T) {
"comnum":1,"appEnable":"TRUE","action":"Resume"}
]}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

ctx := ContextWithDebugLogger(context.Background(), t)
Expand Down Expand Up @@ -158,11 +140,7 @@ func TestHosts(t *testing.T) {
func TestUsersCSRF(t *testing.T) {
body := `{"errCode":"000","errMsg":"","CSRF":"abcdefgh1234.4321abcdefgh"}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)

d := testCableModem(srv)
ctx := ContextWithDebugLogger(context.Background(), t)
Expand Down
56 changes: 10 additions & 46 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hitron
import (
"context"
"net"
"net/http"
"net/http/httptest"
"testing"
"time"
Expand Down Expand Up @@ -47,11 +46,7 @@ func TestRouterSysInfo(t *testing.T) {
"routerMode":"Dualstack"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterSysInfo(context.Background())
Expand Down Expand Up @@ -129,6 +124,7 @@ func TestRouterSysInfo(t *testing.T) {
"lanAsWanMode": "0",
"privLanIp": "192.168.0.1\/24"
}`
srv = staticResponseServer(t, body)

d = testCableModem(srv)

Expand Down Expand Up @@ -262,11 +258,7 @@ func TestRouterCapability(t *testing.T) {
"HnapOnOff":"OFF","UsbOnOff":"OFF","sipAlgOnOff":"OFF"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterCapability(context.Background())
Expand All @@ -284,11 +276,7 @@ func TestRouterCapability(t *testing.T) {
func TestRouterLocation(t *testing.T) {
body := `{"errCode":"000","errMsg":"","locationText":"Basement"}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterLocation(context.Background())
Expand All @@ -306,11 +294,7 @@ func TestRouterDMZ(t *testing.T) {
"privateLan":"192.168.0.1","subMask":"255.255.255.0"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterDMZ(context.Background())
Expand All @@ -331,11 +315,7 @@ func TestRouterPortForwardStatus(t *testing.T) {
"privateLan":"192.168.0.1","subMask":"255.255.255.0"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterPortForwardStatus(context.Background())
Expand Down Expand Up @@ -364,11 +344,7 @@ func TestRouterPortForwardall(t *testing.T) {
"ruleOnOff":"OFF","origin":"1","id":"2"}
]}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterPortForwardall(context.Background())
Expand Down Expand Up @@ -405,11 +381,7 @@ func TestRouterPortTriggerStatus(t *testing.T) {
"allRulesOnOff":"ON"
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterPortTriggerStatus(context.Background())
Expand All @@ -429,11 +401,7 @@ func TestRouterPortTriggerall(t *testing.T) {
"timeout":"50","twowayOnOff":"ON","id":"1"}
]}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterPortTriggerall(context.Background())
Expand All @@ -459,11 +427,7 @@ func TestRouterPortTriggerall(t *testing.T) {
func TestRouterTR069(t *testing.T) {
body := `{"errCode":"000","errMsg":"","tr069url":"http://example.com"}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))

defer srv.Close()
srv := staticResponseServer(t, body)
d := testCableModem(srv)

p, err := d.RouterTR069(context.Background())
Expand Down
Loading

0 comments on commit 3241cfb

Please sign in to comment.