Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Jan 24, 2024
1 parent abc1b3c commit 9affb94
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
8 changes: 8 additions & 0 deletions processors/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package processors

const (
ExpectedQname = "dnscollector.dev"
ExpectedBufferMsg511 = ".*buffer is full, 511.*"
ExpectedBufferMsg1023 = ".*buffer is full, 1023.*"
ExpectedIdentity = "powerdnspb"
)
13 changes: 5 additions & 8 deletions processors/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ func Test_DnsProcessor(t *testing.T) {

// read dns message from dnstap consumer
dmOut := <-fl.GetInputChannel()
if dmOut.DNS.Qname != "dnscollector.dev" {
if dmOut.DNS.Qname != ExpectedQname {
t.Errorf("invalid qname in dns message: %s", dm.DNS.Qname)
}

}

func Test_DnsProcessor_BufferLoggerIsFull(t *testing.T) {
Expand All @@ -58,18 +57,17 @@ func Test_DnsProcessor_BufferLoggerIsFull(t *testing.T) {
// waiting monitor to run in consumer
time.Sleep(12 * time.Second)

regxp := ".*buffer is full, 511.*"
for entry := range logsChan {
fmt.Println(entry)
pattern := regexp.MustCompile(regxp)
pattern := regexp.MustCompile(ExpectedBufferMsg511)
if pattern.MatchString(entry.Message) {
break
}
}

// read dns message from dnstap consumer
dmOut := <-fl.GetInputChannel()
if dmOut.DNS.Qname != "dnscollector.dev" {
if dmOut.DNS.Qname != ExpectedQname {
t.Errorf("invalid qname in dns message: %s", dmOut.DNS.Qname)
}

Expand All @@ -81,18 +79,17 @@ func Test_DnsProcessor_BufferLoggerIsFull(t *testing.T) {
// waiting monitor to run in consumer
time.Sleep(12 * time.Second)

regxp = ".*buffer is full, 1023.*"
for entry := range logsChan {
fmt.Println(entry)
pattern := regexp.MustCompile(regxp)
pattern := regexp.MustCompile(ExpectedBufferMsg1023)
if pattern.MatchString(entry.Message) {
break
}
}

// read dns message from dnstap consumer
dm2 := <-fl.GetInputChannel()
if dm2.DNS.Qname != "dnscollector.dev" {
if dm2.DNS.Qname != ExpectedQname {
t.Errorf("invalid qname in second dns message: %s", dm2.DNS.Qname)
}
}
16 changes: 7 additions & 9 deletions processors/dnstap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Test_DnstapProcessor(t *testing.T) {

// prepare dns query
dnsmsg := new(dns.Msg)
dnsmsg.SetQuestion("www.google.fr.", dns.TypeA)
dnsmsg.SetQuestion(ExpectedQname+".", dns.TypeA)
dnsquestion, _ := dnsmsg.Pack()

// prepare dnstap
Expand All @@ -49,7 +49,7 @@ func Test_DnstapProcessor(t *testing.T) {

// read dns message from dnstap consumer
dm := <-fl.GetInputChannel()
if dm.DNS.Qname != "www.google.fr" {
if dm.DNS.Qname != ExpectedQname {
t.Errorf("invalid qname in dns message: %s", dm.DNS.Qname)
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ func Test_DnstapProcessor_BufferLoggerIsFull(t *testing.T) {

// prepare dns query
dnsmsg := new(dns.Msg)
dnsmsg.SetQuestion("www.google.fr.", dns.TypeA)
dnsmsg.SetQuestion(ExpectedQname+".", dns.TypeA)
dnsquestion, _ := dnsmsg.Pack()

// prepare dnstap
Expand All @@ -315,18 +315,17 @@ func Test_DnstapProcessor_BufferLoggerIsFull(t *testing.T) {
// waiting monitor to run in consumer
time.Sleep(12 * time.Second)

regxp := ".*buffer is full, 511.*"
for entry := range logsChan {
fmt.Println(entry)
pattern := regexp.MustCompile(regxp)
pattern := regexp.MustCompile(ExpectedBufferMsg511)
if pattern.MatchString(entry.Message) {
break
}
}

// read dns message from dnstap consumer
dm := <-fl.GetInputChannel()
if dm.DNS.Qname != "www.google.fr" {
if dm.DNS.Qname != ExpectedQname {
t.Errorf("invalid qname in dns message: %s", dm.DNS.Qname)
}

Expand All @@ -338,18 +337,17 @@ func Test_DnstapProcessor_BufferLoggerIsFull(t *testing.T) {
// waiting monitor to run in consumer
time.Sleep(12 * time.Second)

regxp = ".*buffer is full, 1023.*"
for entry := range logsChan {
fmt.Println(entry)
pattern := regexp.MustCompile(regxp)
pattern := regexp.MustCompile(ExpectedBufferMsg1023)
if pattern.MatchString(entry.Message) {
break
}
}

// read dns message from dnstap consumer
dm2 := <-fl.GetInputChannel()
if dm2.DNS.Qname != "www.google.fr" {
if dm2.DNS.Qname != ExpectedQname {
t.Errorf("invalid qname in second dns message: %s", dm2.DNS.Qname)
}
}
18 changes: 8 additions & 10 deletions processors/powerdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Test_PowerDNSProcessor(t *testing.T) {
dnsQuestion := powerdns_protobuf.PBDNSMessage_DNSQuestion{QName: &dnsQname}

dm := &powerdns_protobuf.PBDNSMessage{}
dm.ServerIdentity = []byte("powerdnspb")
dm.ServerIdentity = []byte(ExpectedIdentity)
dm.Type = powerdns_protobuf.PBDNSMessage_DNSQueryType.Enum()
dm.SocketProtocol = powerdns_protobuf.PBDNSMessage_DNSCryptUDP.Enum()
dm.SocketFamily = powerdns_protobuf.PBDNSMessage_INET.Enum()
Expand All @@ -41,7 +41,7 @@ func Test_PowerDNSProcessor(t *testing.T) {

// read dns message from dnstap consumer
msg := <-fl.GetInputChannel()
if msg.DNSTap.Identity != "powerdnspb" {
if msg.DNSTap.Identity != ExpectedIdentity {
t.Errorf("invalid identity in dns message: %s", msg.DNSTap.Identity)
}
}
Expand All @@ -58,7 +58,7 @@ func Test_PowerDNSProcessor_AddDNSPayload_Valid(t *testing.T) {
dnsQuestion := powerdns_protobuf.PBDNSMessage_DNSQuestion{QName: &dnsQname}

dm := &powerdns_protobuf.PBDNSMessage{}
dm.ServerIdentity = []byte("powerdnspb")
dm.ServerIdentity = []byte(ExpectedIdentity)
dm.Id = proto.Uint32(2000)
dm.Type = powerdns_protobuf.PBDNSMessage_DNSQueryType.Enum()
dm.SocketProtocol = powerdns_protobuf.PBDNSMessage_DNSCryptUDP.Enum()
Expand Down Expand Up @@ -228,7 +228,7 @@ func Test_PowerDNSProcessor_BufferLoggerIsFull(t *testing.T) {
dnsQuestion := powerdns_protobuf.PBDNSMessage_DNSQuestion{QName: &dnsQname}

dm := &powerdns_protobuf.PBDNSMessage{}
dm.ServerIdentity = []byte("powerdnspb")
dm.ServerIdentity = []byte(ExpectedIdentity)
dm.Type = powerdns_protobuf.PBDNSMessage_DNSQueryType.Enum()
dm.SocketProtocol = powerdns_protobuf.PBDNSMessage_DNSCryptUDP.Enum()
dm.SocketFamily = powerdns_protobuf.PBDNSMessage_INET.Enum()
Expand All @@ -248,18 +248,17 @@ func Test_PowerDNSProcessor_BufferLoggerIsFull(t *testing.T) {
// waiting monitor to run in consumer
time.Sleep(12 * time.Second)

regxp := ".*buffer is full, 511.*"
for entry := range logsChan {
fmt.Println(entry)
pattern := regexp.MustCompile(regxp)
pattern := regexp.MustCompile(ExpectedBufferMsg511)
if pattern.MatchString(entry.Message) {
break
}
}

// read dns message from dnstap consumer
msg := <-fl.GetInputChannel()
if msg.DNSTap.Identity != "powerdnspb" {
if msg.DNSTap.Identity != ExpectedIdentity {
t.Errorf("invalid identity in dns message: %s", msg.DNSTap.Identity)
}

Expand All @@ -270,18 +269,17 @@ func Test_PowerDNSProcessor_BufferLoggerIsFull(t *testing.T) {

// waiting monitor to run in consumer
time.Sleep(12 * time.Second)
regxp = ".*buffer is full, 1023.*"
for entry := range logsChan {
fmt.Println(entry)
pattern := regexp.MustCompile(regxp)
pattern := regexp.MustCompile(ExpectedBufferMsg1023)
if pattern.MatchString(entry.Message) {
break
}
}

// read just one dns message from dnstap consumer
msg2 := <-fl.GetInputChannel()
if msg2.DNSTap.Identity != "powerdnspb" {
if msg2.DNSTap.Identity != ExpectedIdentity {
t.Errorf("invalid identity in second dns message: %s", msg2.DNSTap.Identity)
}
}

0 comments on commit 9affb94

Please sign in to comment.