mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-24 14:05:45 +03:00
1e939703e5
Updates #6053. Squashed commit of the following: commit b71957f87eca93e9827d027c246d2ca9d7a7f45a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 9 16:12:10 2023 +0300 all: docs commit 3e394fb2d723c4e305ea91f10fffc866f0b9948a Merge: f406a5ff4c47509fab
Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 9 15:15:37 2023 +0300 all: imp code commit f406a5ff4977acdcd19557969bd405747b84ebbc Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 9 15:05:43 2023 +0300 all: imp code commit 0de1e0e8a9f0dfd3a0ff0c9e787d6e50cf2a1ee8 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 9 14:45:21 2023 +0300 all: docs commit d98cbafe62edd77afcf6c760e28cb5e7632a993e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 9 11:54:39 2023 +0300 dnsforward: https blocked rcode commit c13ffda6182920f97fe8293a9c0b518bbf77956e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 9 10:45:27 2023 +0300 dnsforward: imp tests commit 9c5bc29b33d53ba82ca11f508391e5b5d534a834 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 9 10:08:06 2023 +0300 dnsforward: imp code commit d6ff28b9c277c24b4f273cd4b292543ead13d859 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 8 16:00:15 2023 +0300 all: imp code commit 832b59965d1515badd0a0650f9753fc2985dff1c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 8 13:32:15 2023 +0300 dnsforward: https filtering commit 6a2bdd11331ffddb13bac4e05de85b6661360783 Merge: 257a1b6b854aee2272
Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 8 11:44:12 2023 +0300 Merge remote-tracking branch 'origin/master' into 6053-https-filtering # Conflicts: # CHANGELOG.md commit 257a1b6b868826cb4112c1c88b177290242d3fdd Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 8 11:26:13 2023 +0300 dnsforward: imp tests commit edba217a72101b8b5a79e7b82614b3ea0e4c1f09 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Aug 4 15:03:02 2023 +0300 dnsforward: https filtering commit 4c93be3e0c7b98c1242b60ba5a3c45cea2775be4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Aug 4 14:36:33 2023 +0300 docs: https filtering commit 1d2d1aa3b4ce7a994395fade2f87b2d88d68ac63 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Aug 4 12:54:05 2023 +0300 all: https filtering hints
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
// Package aghtest contains utilities for testing.
|
|
package aghtest
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"io"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/golibs/log"
|
|
)
|
|
|
|
const (
|
|
// ReqHost is the common request host for filtering tests.
|
|
ReqHost = "www.host.example"
|
|
|
|
// ReqFQDN is the common request FQDN for filtering tests.
|
|
ReqFQDN = ReqHost + "."
|
|
)
|
|
|
|
// ReplaceLogWriter moves logger output to w and uses Cleanup method of t to
|
|
// revert changes.
|
|
func ReplaceLogWriter(t testing.TB, w io.Writer) {
|
|
t.Helper()
|
|
|
|
prev := log.Writer()
|
|
t.Cleanup(func() { log.SetOutput(prev) })
|
|
log.SetOutput(w)
|
|
}
|
|
|
|
// ReplaceLogLevel sets logging level to l and uses Cleanup method of t to
|
|
// revert changes.
|
|
func ReplaceLogLevel(t testing.TB, l log.Level) {
|
|
t.Helper()
|
|
|
|
switch l {
|
|
case log.INFO, log.DEBUG, log.ERROR:
|
|
// Go on.
|
|
default:
|
|
t.Fatalf("wrong l value (must be one of %v, %v, %v)", log.INFO, log.DEBUG, log.ERROR)
|
|
}
|
|
|
|
prev := log.GetLevel()
|
|
t.Cleanup(func() { log.SetLevel(prev) })
|
|
log.SetLevel(l)
|
|
}
|
|
|
|
// HostToIPs is a helper that generates one IPv4 and one IPv6 address from host.
|
|
func HostToIPs(host string) (ipv4, ipv6 net.IP) {
|
|
hash := sha256.Sum256([]byte(host))
|
|
|
|
return net.IP(hash[:4]), net.IP(hash[4:20])
|
|
}
|