micro--go-micro
3e885308a0
Fixes #2988. Brings 'golangci-lint run ./...' to zero issues (was ~373): - errcheck: explicitly ignore fire-and-forget calls with '_ =' (and a small errcheck.exclude-functions list for response writes — json Encoder.Encode, http ResponseWriter.Write, fmt.Fprint*); genuine cases handled. - unused: remove dead code (unexported decls and dead test helpers) and the imports they orphaned. - staticcheck: ST1005 error strings, ST1016 receiver names, S1000/S1017/S1019/ S1023 simplifications, SA4004/SA4006/SA4010 dead code, SA1021 net.IP.Equal, SA6002 (store *[]byte in sync.Pool). - govet: fix a context leak (lostcancel) in internal/util/mdns and move t.Fatal/Fatalf out of goroutines (testinggoroutine) in tests. - ineffassign, unconvert: mechanical fixes. CI: the Lint workflow now runs a blocking full-tree 'golangci-lint run' on pushes and PRs (dropped only-new-issues now that the tree is clean). Verified: go build, go vet, test compilation, and unit tests for the behaviourally-touched packages all pass. Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL Co-authored-by: Claude <noreply@anthropic.com>
62 行
1.1 KiB
Go
62 行
1.1 KiB
Go
package mdns
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestServer_StartStop(t *testing.T) {
|
|
s := makeService(t)
|
|
serv, err := NewServer(&Config{Zone: s, LocalhostChecking: true})
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
defer serv.Shutdown()
|
|
}
|
|
|
|
func TestServer_Lookup(t *testing.T) {
|
|
serv, err := NewServer(&Config{Zone: makeServiceWithServiceName(t, "_foobar._tcp"), LocalhostChecking: true})
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
defer serv.Shutdown()
|
|
|
|
entries := make(chan *ServiceEntry, 1)
|
|
found := false
|
|
doneCh := make(chan struct{})
|
|
go func() {
|
|
select {
|
|
case e := <-entries:
|
|
if e.Name != "hostname._foobar._tcp.local." {
|
|
t.Errorf("bad: %v", e)
|
|
}
|
|
if e.Port != 80 {
|
|
t.Errorf("bad: %v", e)
|
|
}
|
|
if e.Info != "Local web server" {
|
|
t.Errorf("bad: %v", e)
|
|
}
|
|
found = true
|
|
|
|
case <-time.After(80 * time.Millisecond):
|
|
t.Errorf("timeout")
|
|
}
|
|
close(doneCh)
|
|
}()
|
|
|
|
params := &QueryParam{
|
|
Service: "_foobar._tcp",
|
|
Domain: "local",
|
|
Timeout: 50 * time.Millisecond,
|
|
Entries: entries,
|
|
}
|
|
err = Query(params)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
<-doneCh
|
|
if !found {
|
|
t.Fatalf("record not found")
|
|
}
|
|
}
|