| 1 | // Copyright 2016 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local`/ |
| 16 | |
| 17 | import ( |
| 18 | "osscip-go gomod github.com/golang/go/src go1.24.2 os/" |
| 19 | |
| 20 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 21 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 22 | |
| 23 | "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/" |
| 24 | ) |
| 25 | |
| 26 | var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("parsing resolv.conf", func() { |
| 27 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("parses a simple resolv.conf file", func() { |
| 28 | contents := ` |
| 29 | nameserver 192.0.2.0 |
| 30 | nameserver 192.0.2.1 |
| 31 | ` |
| 32 | dns, err := parsescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local`/parse().(contents) |
| 33 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 34 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(*dns).Shouldscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#Should().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#{Nameserversscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Nameservers.: []string{"192.0.2.0", "192.0.2.1"}})) |
| 35 | }) |
| 36 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("ignores comments", func() { |
| 37 | dns, err := parsescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local`/parse().(` |
| 38 | nameserver 192.0.2.0 |
| 39 | ;nameserver 192.0.2.1 |
| 40 | `) |
| 41 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 42 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(*dns).Shouldscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#Should().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#{Nameserversscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Nameservers.: []string{"192.0.2.0"}})) |
| 43 | }) |
| 44 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("parses all fields", func() { |
| 45 | dns, err := parsescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local`/parse().(` |
| 46 | nameserver 192.0.2.0 |
| 47 | nameserver 192.0.2.2 |
| 48 | domain example.com |
| 49 | ;nameserver comment |
| 50 | #nameserver comment |
| 51 | search example.net example.org |
| 52 | search example.gov |
| 53 | options one two three |
| 54 | options four |
| 55 | `) |
| 56 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 57 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(*dns).Shouldscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#Should().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#{ |
| 58 | Nameserversscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Nameservers.: []string{"192.0.2.0", "192.0.2.2"}, |
| 59 | Domainscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Domain.: "example.com", |
| 60 | Searchscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Search.: []string{"example.net", "example.org", "example.gov"}, |
| 61 | Optionsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Options.: []string{"one", "two", "three", "four"}, |
| 62 | })) |
| 63 | }) |
| 64 | }) |
| 65 | |
| 66 | func parsescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local`/parse().(contents string) (*typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#, error) { |
| 67 | f, err := osscip-go gomod github.com/golang/go/src go1.24.2 os/.CreateTempscip-go gomod github.com/golang/go/src go1.24.2 os/CreateTemp().("", "host_local_resolv") |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | defer f.Closescip-go gomod github.com/golang/go/src go1.24.2 os/File#Close().() |
| 72 | defer osscip-go gomod github.com/golang/go/src go1.24.2 os/.Removescip-go gomod github.com/golang/go/src go1.24.2 os/Remove().(f.Namescip-go gomod github.com/golang/go/src go1.24.2 os/File#Name().()) |
| 73 | |
| 74 | if _, err := f.WriteStringscip-go gomod github.com/golang/go/src go1.24.2 os/File#WriteString().(contents); err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | |
| 78 | return parseResolvConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local`/parseResolvConf().(f.Namescip-go gomod github.com/golang/go/src go1.24.2 os/File#Name().()) |
| 79 | } |