Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/sandbox/fixtures/expanded_resolv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
search 1.com 2.com 3.com 4.com 5.com 6.com 7.com
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we clean this up after the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we've already cleaned the output resolv.conf file up after each test.

Expect(sandbox.ParseDNSOptions(c.Servers, c.Searches, c.Options, c.Path)).To(BeNil())
defer os.Remove(c.Path)

Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah the test as it currently is is not quite right. If we do os.Remove(c.Path) after calling Expect(ParseDNSOptions...), it's possible ParseDNSOptions failed after creating the file but before creating. can you switch the order of the defer and Expect calls, and remove this file from the commit?

Copy link
Contributor Author

@gjkim42 gjkim42 Aug 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you switch the order of the defer and Expect calls

That is a good point. Done.

and remove this file from the commit?

I think this file is a test data as fixtures/resolv.conf is. (This file refers to c.Want, not c.Path)

Should we have to refactor the test to be able to test without these files?
Let me know if that is what you request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason I didn't see the fixtures directory when I looked before. We can have the refactor as a follow up (which I'd love if you wanted to take that on 😃 )

nameserver cri-o.io
nameserver github.com
options timeout:5 attempts:3
10 changes: 0 additions & 10 deletions pkg/sandbox/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import (
"golang.org/x/sys/unix"
)

const (
// According to http://man7.org/linux/man-pages/man5/resolv.conf.5.html:
// "The search list is currently limited to six domains with a total of 256 characters."
maxDNSSearches = 6
)

func (s *sandbox) InitInfraContainer(serverConfig *libconfig.Config, podContainer *storage.ContainerInfo) error {
var err error
s.infra, err = container.New()
Expand Down Expand Up @@ -129,10 +123,6 @@ func ParseDNSOptions(servers, searches, options []string, path string) (retErr e
return copyFile("/etc/resolv.conf", path)
}

if nSearches > maxDNSSearches {
return fmt.Errorf("DNSOption.Searches has more than %d domains", maxDNSSearches)
}

f, err := os.Create(path)
if err != nil {
return err
Expand Down
16 changes: 12 additions & 4 deletions pkg/sandbox/infra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

const (
defaultDNSPath = "/etc/resolv.conf"
testDNSPath = "fixtures/resolv_test.conf"
dnsPath = "fixtures/resolv.conf"
defaultDNSPath = "/etc/resolv.conf"
testDNSPath = "fixtures/resolv_test.conf"
dnsPath = "fixtures/resolv.conf"
expandedDNSPath = "fixtures/expanded_resolv.conf"
)

var _ = Describe("Sandbox", func() {
Expand All @@ -36,11 +37,18 @@ var _ = Describe("Sandbox", func() {
[]string{"timeout:5", "attempts:3"},
testDNSPath, dnsPath,
},
{
[]string{"cri-o.io", "github.com"},
[]string{"1.com", "2.com", "3.com", "4.com", "5.com", "6.com", "7.com"},
[]string{"timeout:5", "attempts:3"},
testDNSPath, expandedDNSPath,
},
}

for _, c := range testCases {
Expect(sandbox.ParseDNSOptions(c.Servers, c.Searches, c.Options, c.Path)).To(BeNil())
err := sandbox.ParseDNSOptions(c.Servers, c.Searches, c.Options, c.Path)
defer os.Remove(c.Path)
Expect(err).To(BeNil())

expect, _ := ioutil.ReadFile(c.Want) // nolint: errcheck
result, _ := ioutil.ReadFile(c.Path) // nolint: errcheck
Expand Down