Skip to content

Commit

Permalink
GHactions count tests and number of lines (#466)
Browse files Browse the repository at this point in the history
* GHactions count tests
* add badges
* add tests
  • Loading branch information
dmachard authored Nov 17, 2023
1 parent 9583688 commit 8c0cd2f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 9 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/testing-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,28 @@ jobs:
cd prometheus-$PROM_VERSION.linux-amd64/
curl -u admin:changeme http://127.0.0.1:8081/metrics | ./promtool check metrics
env:
PROM_VERSION: "2.47.0"
PROM_VERSION: "2.47.0"

count:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.21"

- id: count_tests
run: |
data=$(sudo go test -v ./collectors ./processors ./dnsutils ./netlib ./loggers ./transformers 2>&1 | grep -c RUN)
echo "Count of Tests: $data"
echo "data=$data" >> $GITHUB_OUTPUT
- id: count_lines
run: |
data=$(find . -name "*.go" -exec grep -v "^$" {} \; -exec grep -v "//" {} \; | wc -l)
echo "Count of Lines: $data"
echo "data=$data" >> $GITHUB_OUTPUT
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ version: build
lint:
$(GOPATH)/bin/golangci-lint run --config=.golangci.yml ./...

test:
tests:
@go test ./dnsutils/ -race -cover -v
@go test ./netlib/ -race -cover -v
@go test -timeout 30s ./transformers/ -race -cover -v
@go test -timeout 30s ./collectors/ -race -cover -v
@go test -timeout 90s ./loggers/ -race -cover -v
@go test -timeout 30s ./processors/ -race -cover -v

clean:
@go clean
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Go Report Card](https://goreportcard.com/badge/github.com/dmachard/go-dns-collector)](https://goreportcard.com/report/dmachard/go-dns-collector)
![Go version](https://img.shields.io/badge/go%20version-min%201.20-blue)
![Go tests](https://img.shields.io/badge/go%20tests-333-green)
![Go lines](https://img.shields.io/badge/go%20lines-47871-red)

![Go Tests](https://github.com/dmachard/go-dns-collector/actions/workflows/testing-go.yml/badge.svg)
![Github Actions](https://github.com/dmachard/go-dns-collector/actions/workflows/testing-dnstap.yml/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion dnsutils/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ func GetFakeDnsMessage() DnsMessage {
func GetFakeDnsMessageWithPayload() DnsMessage {
// fake dns query payload
dnsmsg := new(dns.Msg)
dnsmsg.SetQuestion("dnscollector.dev.", dns.TypeA)
dnsmsg.SetQuestion("dnscollector.dev.", dns.TypeAAAA)
dnsquestion, _ := dnsmsg.Pack()

dm := GetFakeDnsMessage()
Expand Down
1 change: 0 additions & 1 deletion docs/collectors/collector_powerdns.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ powerdns:
sock-rcvbuf: 0
reset-conn: true
chan-buffer-size: 65535
add-dns-payload: false
```
The DNS-collector has a full [Protobuf Logging](https://dnsdist.org/reference/protobuf.html) support for PowerDNS's products.
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ make lint
Execute testunits before to commit

```bash
sudo make test
sudo make tests
```

Execute a test for one specific testcase in a package
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_loki.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Options:
- `flush-interval`: (integer) flush batch every X seconds
- `batch-size`: (integer) batch size for log entries in bytes
- `retry-interval`: (integer) interval in second between before to retry to send batch
- `text-format`: (string) output text format, please refer to the default text format to see all available directives, use this parameter if you want a specific format
- `text-format`: (string) output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
- `proxy-url`: (string) Proxy URL
- `tls-insecure`: (boolean) insecure tls, skip certificate and hostname verify
- `tls-min-version`: (string) min tls version
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Redis Pub logger
Options:

* `transport`: (string) network transport to use: `tcp`|`unix`|`tcp+tls`
* `remote-ip`: (string) remote address
* `remote-address`: (string) remote IP or host address
* `remote-port`: (integer) remote tcp port
* `sock-path` **DEPRECATED, replaced by remote-address**: (string) unix socket path
* `connect-timeout`: (integer) connect timeout in second
Expand Down
4 changes: 2 additions & 2 deletions docs/loggers/logger_stdout.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Print to your standard output, all DNS logs received

Options:

* `mode`: (string) output format: text, json, flat-json or pcap
* `text-format`: (string) output text format, please refer to the default text format to see all available directives, use this parameter if you want a specific format
* `mode`: (string) output format: `text`, `json`, `flat-json` or `pcap`
* `text-format`: (string) output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
* `chan-buffer-size`: (integer) channel buffer size used on incoming dns message, number of messages before to drop it.

Default values:
Expand Down
31 changes: 31 additions & 0 deletions processors/dns_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package processors

import (
"bytes"
"testing"

"github.com/dmachard/go-dnscollector/dnsutils"
"github.com/dmachard/go-logger"
)

func Test_DnsProcessor(t *testing.T) {
logger := logger.New(true)
var o bytes.Buffer
logger.SetOutput(&o)

// init and run the dns processor
consumer := NewDnsProcessor(dnsutils.GetFakeConfig(), logger, "test", 512)
chan_to := make(chan dnsutils.DnsMessage, 512)
go consumer.Run([]chan dnsutils.DnsMessage{chan_to}, []string{"test"})

dm := dnsutils.GetFakeDnsMessageWithPayload()
consumer.GetChannel() <- dm

// read dns message from dnstap consumer
dmOut := <-chan_to

if dmOut.DNS.Qname != "dnscollector.dev" {
t.Errorf("invalid qname in dns message: %s", dm.DNS.Qname)
}

}

0 comments on commit 8c0cd2f

Please sign in to comment.