-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle original search domains in resolv.conf type implementations. - parse the original resolv.conf file - merge the search domains - ignore the domain keyword - append any other config lines (sortstlist, options) - fix read origin resolv.conf from bkp in resolvconf implementation - fix line length validation - fix number of search domains validation
- Loading branch information
Showing
3 changed files
with
247 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package dns | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test_mergeSearchDomains(t *testing.T) { | ||
searchDomains := []string{"a", "b"} | ||
originDomains := []string{"a", "b"} | ||
mergedDomains := mergeSearchDomains(searchDomains, originDomains) | ||
if len(mergedDomains) != 4 { | ||
t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 4) | ||
} | ||
} | ||
|
||
func Test_mergeSearchTooMuchDomains(t *testing.T) { | ||
searchDomains := []string{"a", "b", "c", "d", "e", "f", "g"} | ||
originDomains := []string{"h", "i"} | ||
mergedDomains := mergeSearchDomains(searchDomains, originDomains) | ||
if len(mergedDomains) != 6 { | ||
t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 6) | ||
} | ||
} | ||
|
||
func Test_mergeSearchTooMuchDomainsInOrigin(t *testing.T) { | ||
searchDomains := []string{"a", "b"} | ||
originDomains := []string{"c", "d", "e", "f", "g"} | ||
mergedDomains := mergeSearchDomains(searchDomains, originDomains) | ||
if len(mergedDomains) != 6 { | ||
t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 6) | ||
} | ||
} | ||
|
||
func Test_mergeSearchTooLongDomain(t *testing.T) { | ||
searchDomains := []string{getLongLine()} | ||
originDomains := []string{"b"} | ||
mergedDomains := mergeSearchDomains(searchDomains, originDomains) | ||
if len(mergedDomains) != 1 { | ||
t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 1) | ||
} | ||
|
||
searchDomains = []string{"b"} | ||
originDomains = []string{getLongLine()} | ||
|
||
mergedDomains = mergeSearchDomains(searchDomains, originDomains) | ||
if len(mergedDomains) != 1 { | ||
t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 1) | ||
} | ||
} | ||
|
||
func getLongLine() string { | ||
x := "search " | ||
for { | ||
for i := 0; i <= 9; i++ { | ||
if len(x) > fileMaxLineCharsLimit { | ||
return x | ||
} | ||
x = fmt.Sprintf("%s%d", x, i) | ||
} | ||
} | ||
} |
Oops, something went wrong.