mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
lint: enable protogetter linter (#7336)
Enable protogetter in golangci config and update all protobuf field access to use getter methods instead of direct field access. Getter methods provide safer nil pointer handling and return appropriate default values, following protobuf best practices. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
@@ -47,23 +47,37 @@ func (w *writer) Dnstap(e *tap.Dnstap) {
|
||||
w.t.Error("Message not expected")
|
||||
}
|
||||
|
||||
ex := w.queue[0].Message
|
||||
got := e.Message
|
||||
ex := w.queue[0].GetMessage()
|
||||
got := e.GetMessage()
|
||||
|
||||
if string(ex.QueryAddress) != string(got.QueryAddress) {
|
||||
w.t.Errorf("Expected source address %s, got %s", ex.QueryAddress, got.QueryAddress)
|
||||
eaddr := string(ex.GetQueryAddress())
|
||||
gaddr := string(got.GetQueryAddress())
|
||||
if eaddr != gaddr {
|
||||
w.t.Errorf("Expected source address %s, got %s", eaddr, gaddr)
|
||||
}
|
||||
if string(ex.ResponseAddress) != string(got.ResponseAddress) {
|
||||
w.t.Errorf("Expected response address %s, got %s", ex.ResponseAddress, got.ResponseAddress)
|
||||
|
||||
eraddr := string(ex.GetResponseAddress())
|
||||
graddr := string(got.GetResponseAddress())
|
||||
if eraddr != graddr {
|
||||
w.t.Errorf("Expected response address %s, got %s", eraddr, graddr)
|
||||
}
|
||||
if *ex.QueryPort != *got.QueryPort {
|
||||
w.t.Errorf("Expected port %d, got %d", *ex.QueryPort, *got.QueryPort)
|
||||
|
||||
ep := ex.GetQueryPort()
|
||||
gp := got.GetQueryPort()
|
||||
if ep != gp {
|
||||
w.t.Errorf("Expected port %d, got %d", ep, gp)
|
||||
}
|
||||
if *ex.SocketFamily != *got.SocketFamily {
|
||||
w.t.Errorf("Expected socket family %d, got %d", *ex.SocketFamily, *got.SocketFamily)
|
||||
|
||||
ef := ex.GetSocketFamily()
|
||||
sf := got.GetSocketFamily()
|
||||
if ef != sf {
|
||||
w.t.Errorf("Expected socket family %d, got %d", ef, sf)
|
||||
}
|
||||
if string(w.queue[0].Extra) != string(e.Extra) {
|
||||
w.t.Errorf("Expected extra %s, got %s", w.queue[0].Extra, e.Extra)
|
||||
|
||||
eext := string(w.queue[0].GetExtra())
|
||||
gext := string(e.GetExtra())
|
||||
if eext != gext {
|
||||
w.t.Errorf("Expected extra %s, got %s", eext, gext)
|
||||
}
|
||||
w.queue = w.queue[1:]
|
||||
}
|
||||
@@ -80,23 +94,23 @@ func TestDnstap(t *testing.T) {
|
||||
tapq := &tap.Dnstap{
|
||||
Message: testMessage(),
|
||||
}
|
||||
msg.SetType(tapq.Message, tap.Message_CLIENT_QUERY)
|
||||
msg.SetType(tapq.GetMessage(), tap.Message_CLIENT_QUERY)
|
||||
tapr := &tap.Dnstap{
|
||||
Message: testMessage(),
|
||||
}
|
||||
msg.SetType(tapr.Message, tap.Message_CLIENT_RESPONSE)
|
||||
msg.SetType(tapr.GetMessage(), tap.Message_CLIENT_RESPONSE)
|
||||
testCase(t, tapq, tapr, q, r, "")
|
||||
|
||||
tapq_with_extra := &tap.Dnstap{
|
||||
Message: testMessage(), // leave type unset for deepEqual
|
||||
Extra: []byte("extra_field_MetadataValue_A_example.org._IN_udp_29_10.240.0.1_40212_127.0.0.1"),
|
||||
}
|
||||
msg.SetType(tapq_with_extra.Message, tap.Message_CLIENT_QUERY)
|
||||
msg.SetType(tapq_with_extra.GetMessage(), tap.Message_CLIENT_QUERY)
|
||||
tapr_with_extra := &tap.Dnstap{
|
||||
Message: testMessage(),
|
||||
Extra: []byte("extra_field_MetadataValue_A_example.org._IN_udp_29_10.240.0.1_40212_127.0.0.1"),
|
||||
}
|
||||
msg.SetType(tapr_with_extra.Message, tap.Message_CLIENT_RESPONSE)
|
||||
msg.SetType(tapr_with_extra.GetMessage(), tap.Message_CLIENT_RESPONSE)
|
||||
extraFormat := "extra_field_{/metadata/test}_{type}_{name}_{class}_{proto}_{size}_{remote}_{port}_{local}"
|
||||
testCase(t, tapq_with_extra, tapr_with_extra, q, r, extraFormat)
|
||||
}
|
||||
@@ -120,7 +134,7 @@ func TestTapMessage(t *testing.T) {
|
||||
// extra field would not be replaced, since TapMessage won't pass context
|
||||
Extra: []byte(extraFormat),
|
||||
}
|
||||
msg.SetType(tapq.Message, tap.Message_CLIENT_QUERY)
|
||||
msg.SetType(tapq.GetMessage(), tap.Message_CLIENT_QUERY)
|
||||
|
||||
w := writer{t: t}
|
||||
w.queue = append(w.queue, tapq)
|
||||
@@ -132,5 +146,5 @@ func TestTapMessage(t *testing.T) {
|
||||
io: &w,
|
||||
ExtraFormat: extraFormat,
|
||||
}
|
||||
h.TapMessage(tapq.Message)
|
||||
h.TapMessage(tapq.GetMessage())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user