github.com/roboticscm/goman@v0.0.0-20210203095141-87c07b4a0a55/src/net/dnsconfig_unix_test.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 7 package net 8 9 import ( 10 "reflect" 11 "testing" 12 ) 13 14 var dnsReadConfigTests = []struct { 15 name string 16 conf dnsConfig 17 }{ 18 { 19 name: "testdata/resolv.conf", 20 conf: dnsConfig{ 21 servers: []string{"8.8.8.8", "2001:4860:4860::8888", "fe80::1%lo0"}, 22 search: []string{"localdomain"}, 23 ndots: 5, 24 timeout: 10, 25 attempts: 3, 26 rotate: true, 27 }, 28 }, 29 { 30 name: "testdata/domain-resolv.conf", 31 conf: dnsConfig{ 32 servers: []string{"8.8.8.8"}, 33 search: []string{"localdomain"}, 34 ndots: 1, 35 timeout: 5, 36 attempts: 2, 37 }, 38 }, 39 { 40 name: "testdata/search-resolv.conf", 41 conf: dnsConfig{ 42 servers: []string{"8.8.8.8"}, 43 search: []string{"test", "invalid"}, 44 ndots: 1, 45 timeout: 5, 46 attempts: 2, 47 }, 48 }, 49 { 50 name: "testdata/empty-resolv.conf", 51 conf: dnsConfig{ 52 ndots: 1, 53 timeout: 5, 54 attempts: 2, 55 }, 56 }, 57 } 58 59 func TestDNSReadConfig(t *testing.T) { 60 for _, tt := range dnsReadConfigTests { 61 conf, err := dnsReadConfig(tt.name) 62 if err != nil { 63 t.Fatal(err) 64 } 65 if !reflect.DeepEqual(conf, &tt.conf) { 66 t.Errorf("got %v; want %v", conf, &tt.conf) 67 } 68 } 69 }