Skip to content

Commit

Permalink
BREAKING CHANGE: update the data format (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone authored Nov 29, 2024
1 parent d5a39c8 commit 81d3408
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 31 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.23.3

require (
github.com/miekg/dns v1.1.62
github.com/rbmk-project/common v0.3.0
github.com/rbmk-project/dnscore v0.5.0
github.com/rbmk-project/x v0.0.0-20241128223009-259541ec264e
github.com/rbmk-project/common v0.4.0
github.com/rbmk-project/dnscore v0.6.0
github.com/rbmk-project/x v0.0.0-20241129091418-83d898f771ef
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
)
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rbmk-project/common v0.3.0 h1:g9iX/lg5kvzmgxgr4xbkcCjA2jfazM1zAyLKzLD/3iU=
github.com/rbmk-project/common v0.3.0/go.mod h1:uzrFIJl8SEOpgS2pSeBFLUgqc4D1lIcGk/EYuxkFO0U=
github.com/rbmk-project/dnscore v0.5.0 h1:GaWr4SUJFJzjAgkZ9kJdS0I0BWHPnObD/lZaZzPfB9c=
github.com/rbmk-project/dnscore v0.5.0/go.mod h1:ENuxqOG44rTIByt412eghWPRvTg/G5RkE6Truv+tapQ=
github.com/rbmk-project/x v0.0.0-20241128223009-259541ec264e h1:21oFW1k4wE3HMKIOFU+ybK3IA16CxqhMJO9GzAG44p0=
github.com/rbmk-project/x v0.0.0-20241128223009-259541ec264e/go.mod h1:oX91OYzYwrZfFYo91YGcRo2mCa7OthoQuwiXMjKSswE=
github.com/rbmk-project/common v0.4.0 h1:gw7f/YdPxcUZ81cO9IMzEPDhsc6tOUte1m0OFi6euFg=
github.com/rbmk-project/common v0.4.0/go.mod h1:uzrFIJl8SEOpgS2pSeBFLUgqc4D1lIcGk/EYuxkFO0U=
github.com/rbmk-project/dnscore v0.6.0 h1:23rRsLBwTkQqJQMVPf4kimzGSZsw29EY7u3ffHbWkKg=
github.com/rbmk-project/dnscore v0.6.0/go.mod h1:Ct9RhR8HTI6tnq6/HSbzB/F8bk3k7E/6hmEctxSecUQ=
github.com/rbmk-project/x v0.0.0-20241129091418-83d898f771ef h1:4+h9APkbuAP1d1PMQ4K279Rpe+J5XRHKf+3z85RHE9o=
github.com/rbmk-project/x v0.0.0-20241129091418-83d898f771ef/go.mod h1:1Du1EHDkRs9D7MmpLPKAuBzZuJXRbvpBbefW0bTBVbs=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
71 changes: 49 additions & 22 deletions internal/qa/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,27 @@ type Event struct {
// I/O operations
//

// Count is the number of bytes read or written.
Count int64 `json:"count,omitempty"`
// IOBufferSize is the size of the I/O buffer.
IOBufferSize int64 `json:"ioBufferSize,omitempty"`

// IOBytesCount is the number of bytes read or written.
IOBytesCount int64 `json:"ioBytesCount,omitempty"`

//
// DNS-specific fields
//

// RawQuery contains the raw DNS query message.
RawQuery []byte `json:"rawQuery,omitempty"`
// DNSRawQuery is the raw DNS query.
DNSRawQuery []byte `json:"dnsRawQuery,omitempty"`

// DNSRawResponse is the raw DNS response.
DNSRawResponse []byte `json:"dnsRawResponse,omitempty"`

// DNSLookupDomain is the domain passed to LookupHost.
DNSLookupDomain string `json:"dnsLookupDomain,omitempty"`

// RawResponse contains the raw DNS response message.
RawResponse []byte `json:"rawResponse,omitempty"`
// DNSResolvedAddrs is the list of resolved addresses.
DNSResolvedAddrs []string `json:"dnsResolvedAddrs,omitempty"`

//
// Server-specific fields
Expand Down Expand Up @@ -150,37 +159,43 @@ func (ev *Event) VerifyReadWriteClose(t Driver) {
ev.verifyEndpoint(t, ev.LocalAddr)
ev.verifyEndpoint(t, ev.RemoteAddr)
ev.verifyErrEmpty(t)
ev.verifyCountPositive(t)
ev.verifyIOBufferSizePositive(t)
ev.verifyIOBytesCountZero(t)

case "closeStart":
ev.verifyStartEventTime(t)
ev.verifyProtocol(t)
ev.verifyEndpoint(t, ev.LocalAddr)
ev.verifyEndpoint(t, ev.RemoteAddr)
ev.verifyErrEmpty(t)
ev.verifyCountZero(t)
ev.verifyIOBufferSizeZero(t)
ev.verifyIOBytesCountZero(t)

case "readDone", "writeDone":
ev.verifyDoneEventTime(t)
ev.verifyProtocol(t)
ev.verifyEndpoint(t, ev.LocalAddr)
ev.verifyEndpoint(t, ev.RemoteAddr)
ev.verifyCountOrErr(t)
ev.verifyIOBufferSizeZero(t)
ev.verifyIOBytesCountOrErr(t)

case "closeDone":
ev.verifyDoneEventTime(t)
ev.verifyProtocol(t)
ev.verifyEndpoint(t, ev.LocalAddr)
ev.verifyEndpoint(t, ev.RemoteAddr)
// any value of error is okay
ev.verifyCountZero(t)
ev.verifyIOBufferSizeZero(t)
ev.verifyIOBytesCountZero(t)

default:
require.Fail(t, "unexpected message %q", ev.Msg)
}

ev.verifyRawQueryEmpty(t)
ev.verifyRawResponseEmpty(t)
ev.verifyDNSRawQueryEmpty(t)
ev.verifyDNSRawResponseEmpty(t)
ev.verifyDNSLookupDomainEmpty(t)
ev.verifyDNSResolverAddrsEmpty(t)
ev.verifyServerAddrEmpty(t)
ev.verifyServerProtocolEmpty(t)
ev.verifyTLSServerNameEmpty(t)
Expand Down Expand Up @@ -221,24 +236,36 @@ func (ev *Event) verifyErrEmpty(t Driver) {
require.Empty(t, ev.Err, "expected empty error field")
}

func (ev *Event) verifyCountPositive(t Driver) {
require.True(t, ev.Count > 0, "expected positive count field")
func (ev *Event) verifyIOBufferSizePositive(t Driver) {
require.True(t, ev.IOBufferSize > 0, "expected positive ioBufferSize field")
}

func (ev *Event) verifyIOBufferSizeZero(t Driver) {
require.Zero(t, ev.IOBufferSize, "expected zero ioBufferSize field")
}

func (ev *Event) verifyIOBytesCountZero(t Driver) {
require.Zero(t, ev.IOBytesCount, "expected zero ioBytesCount field")
}

func (ev *Event) verifyIOBytesCountOrErr(t Driver) {
require.True(t, ev.IOBytesCount > 0 || ev.Err != "", "expected ioBytesCount > 0 or err != \"\"")
}

func (ev *Event) verifyCountZero(t Driver) {
require.Zero(t, ev.Count, "expected zero count field")
func (ev *Event) verifyDNSRawQueryEmpty(t Driver) {
require.Empty(t, ev.DNSRawQuery, "expected empty dnsRawQuery field")
}

func (ev *Event) verifyCountOrErr(t Driver) {
require.True(t, ev.Count > 0 || ev.Err != "", "expected count or error")
func (ev *Event) verifyDNSRawResponseEmpty(t Driver) {
require.Empty(t, ev.DNSRawResponse, "expected empty dnsRawResponse field")
}

func (ev *Event) verifyRawQueryEmpty(t Driver) {
require.Empty(t, ev.RawQuery, "expected empty rawQuery field")
func (ev *Event) verifyDNSLookupDomainEmpty(t Driver) {
require.Empty(t, ev.DNSLookupDomain, "expected empty dnsLookupDomain field")
}

func (ev *Event) verifyRawResponseEmpty(t Driver) {
require.Empty(t, ev.RawResponse, "expected empty rawResponse field")
func (ev *Event) verifyDNSResolverAddrsEmpty(t Driver) {
require.Empty(t, ev.DNSResolvedAddrs, "expected empty dnsResolvedAddrs field")
}

func (ev *Event) verifyServerAddrEmpty(t Driver) {
Expand Down

0 comments on commit 81d3408

Please sign in to comment.