Skip to content

Commit

Permalink
all: imp docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Apr 25, 2024
1 parent e55129f commit 1b09522
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ mandatory!).
`--upstream=[/host.com/]1.2.3.4 --upstream=[/www.host.com/]2.3.4.5` will send
queries for `*.host.com` to `1.2.3.4`, except `*.www.host.com`, which will go
to `2.3.4.5`.
3. The special server address `#` means, "use the commonxw servers", so:
3. The special server address `#` means, "use the common servers", so:
`--upstream=[/host.com/]1.2.3.4 --upstream=[/www.host.com/]#` will send
queries for `*.host.com` to `1.2.3.4`, except `*.www.host.com` which will be
forwarded as usual.
Expand Down
117 changes: 39 additions & 78 deletions proxy/upstreams_test.go → proxy/upstreams_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,53 @@ import (

// TODO(e.burkov): Call [testing.T.Parallel] in this file.

func TestUpstreamConfig_GetUpstreamsForDomain(t *testing.T) {
t.Parallel()
// Domains specifications and their questions used in tests of [UpstreamConfig].
const (
unqualifiedFQDN = "unqualified."
unspecifiedFQDN = "unspecified.domain."

// Domains specifications and their questions.
const (
unqualifiedFQDN = "unqualified."
unspecifiedFQDN = "unspecified.domain."
topLevelDomain = "example"
topLevelFQDN = topLevelDomain + "."

topLevelDomain = "example"
topLevelFQDN = topLevelDomain + "."
firstLevelDomain = "name." + topLevelDomain
firstLevelFQDN = firstLevelDomain + "."

firstLevelDomain = "name." + topLevelDomain
firstLevelFQDN = firstLevelDomain + "."
subDomain = "sub." + firstLevelDomain
subFQDN = subDomain + "."

subDomain = "sub." + firstLevelDomain
subFQDN = subDomain + "."
generalDomain = "general." + firstLevelDomain
generalFQDN = generalDomain + "."

generalDomain = "general." + firstLevelDomain
generalFQDN = generalDomain + "."
wildcardDomain = "*." + firstLevelDomain
anotherSubFQDN = "another." + firstLevelDomain + "."
)

wildcardDomain = "*." + firstLevelDomain
anotherSubFQDN = "another." + firstLevelDomain + "."
)
// Upstream URLs used in tests of [UpstreamConfig].
const (
generalUpstream = "tcp://general.upstream:53"
unqualifiedUpstream = "tcp://unqualified.upstream:53"
tldUpstream = "tcp://tld.upstream:53"
domainUpstream = "tcp://domain.upstream:53"
wildcardUpstream = "tcp://wildcard.upstream:53"
subdomainUpstream = "tcp://subdomain.upstream:53"
)

// Upstreams.
const (
generalUpstream = "tcp://general.upstream:53"
unqualifiedUpstream = "tcp://unqualified.upstream:53"
tldUpstream = "tcp://tld.upstream:53"
domainUpstream = "tcp://domain.upstream:53"
wildcardUpstream = "tcp://wildcard.upstream:53"
subdomainUpstream = "tcp://subdomain.upstream:53"
)
// testUpstreamConfigLines is the common set of upstream configurations used in
// tests of [UpstreamConfig].
var testUpstreamConfigLines = []string{
generalUpstream,
"[//]" + unqualifiedUpstream,
"[/" + topLevelDomain + "/]" + tldUpstream,
"[/" + firstLevelDomain + "/]" + domainUpstream,
"[/" + wildcardDomain + "/]" + wildcardUpstream,
"[/" + generalDomain + "/]#",
"[/" + subDomain + "/]" + subdomainUpstream,
}

lines := []string{
generalUpstream,
"[//]" + unqualifiedUpstream,
"[/" + topLevelDomain + "/]" + tldUpstream,
"[/" + firstLevelDomain + "/]" + domainUpstream,
"[/" + wildcardDomain + "/]" + wildcardUpstream,
"[/" + generalDomain + "/]#",
"[/" + subDomain + "/]" + subdomainUpstream,
}
func TestUpstreamConfig_GetUpstreamsForDomain(t *testing.T) {
t.Parallel()

config, err := ParseUpstreamsConfig(lines, nil)
config, err := ParseUpstreamsConfig(testUpstreamConfigLines, nil)
require.NoError(t, err)

testCases := []struct {
Expand Down Expand Up @@ -108,48 +110,7 @@ func TestUpstreamConfig_GetUpstreamsForDomain(t *testing.T) {
func TestUpstreamConfig_GetUpstreamsForDS(t *testing.T) {
t.Parallel()

// Domains specifications and their questions.
const (
unqualifiedFQDN = "unqualified."
unspecifiedFQDN = "unspecified.domain."

topLevelDomain = "example"
topLevelFQDN = topLevelDomain + "."

firstLevelDomain = "name." + topLevelDomain
firstLevelFQDN = firstLevelDomain + "."

subDomain = "sub." + firstLevelDomain
subFQDN = subDomain + "."

generalDomain = "general." + firstLevelDomain
generalFQDN = generalDomain + "."

wildcardDomain = "*." + firstLevelDomain
anotherSubFQDN = "another." + firstLevelDomain + "."
)

// Upstreams.
const (
generalUpstream = "tcp://general.upstream:53"
unqualifiedUpstream = "tcp://unqualified.upstream:53"
tldUpstream = "tcp://tld.upstream:53"
domainUpstream = "tcp://domain.upstream:53"
wildcardUpstream = "tcp://wildcard.upstream:53"
subdomainUpstream = "tcp://subdomain.upstream:53"
)

lines := []string{
generalUpstream,
"[//]" + unqualifiedUpstream,
"[/" + topLevelDomain + "/]" + tldUpstream,
"[/" + firstLevelDomain + "/]" + domainUpstream,
"[/" + wildcardDomain + "/]" + wildcardUpstream,
"[/" + generalDomain + "/]#",
"[/" + subDomain + "/]" + subdomainUpstream,
}

config, err := ParseUpstreamsConfig(lines, nil)
config, err := ParseUpstreamsConfig(testUpstreamConfigLines, nil)
require.NoError(t, err)

testCases := []struct {
Expand Down

0 comments on commit 1b09522

Please sign in to comment.