Skip to content

Commit

Permalink
Add component mock
Browse files Browse the repository at this point in the history
  • Loading branch information
vicweiss committed Oct 16, 2024
1 parent e33a05e commit b186c38
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions comp/rdnsquerier/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package mock

import (
"fmt"
"net"
"net/netip"

rdnsquerier "github.com/DataDog/datadog-agent/comp/rdnsquerier/def"
Expand Down Expand Up @@ -51,3 +52,18 @@ func (q *rdnsQuerierMock) GetHostname(ipAddr []byte, updateHostnameSync func(str

return nil
}

// GetHostnameSync simulates resolving the hostname for the given IP address synchronously. If the IP address is in the private address
// space then the resolved hostname is returned.
func (q *rdnsQuerierMock) GetHostnameSync(ipAddr string) (string, error) {
ipaddr := net.ParseIP(ipAddr).To4()
if ipaddr == nil {
return "", fmt.Errorf("invalid IP address %v", ipAddr)
}

if !ipaddr.IsPrivate() {
return "", nil
}

return "hostname-" + ipaddr.String(), nil
}

0 comments on commit b186c38

Please sign in to comment.