(t *testing.T)
| 22 | ` |
| 23 | |
| 24 | func TestResolver_ConfigParsing(t *testing.T) { |
| 25 | logger := log.NewNopLogger() |
| 26 | period := time.Hour // We don't want the periodic reload running in the test |
| 27 | tmpDir := t.TempDir() |
| 28 | |
| 29 | t.Run("missing resolv.conf", func(t *testing.T) { |
| 30 | cfgPath := path.Join(tmpDir, "resolv.conf") |
| 31 | client := newMockClient() |
| 32 | |
| 33 | resolver := NewResolverWithClient(cfgPath, logger, period, client) |
| 34 | t.Cleanup(resolver.Stop) |
| 35 | |
| 36 | conf := resolver.getConfig() |
| 37 | require.Equal(t, []string{"127.0.0.1"}, conf.Servers) |
| 38 | require.Equal(t, 2, conf.Attempts) |
| 39 | }) |
| 40 | |
| 41 | t.Run("attempts not included", func(t *testing.T) { |
| 42 | cfgPath := writeResovConf(t, tmpDir, "nameserver 127.0.0.53\n") |
| 43 | client := newMockClient() |
| 44 | |
| 45 | resolver := NewResolverWithClient(cfgPath, logger, period, client) |
| 46 | t.Cleanup(resolver.Stop) |
| 47 | |
| 48 | conf := resolver.getConfig() |
| 49 | require.Equal(t, []string{"127.0.0.53"}, conf.Servers) |
| 50 | require.Equal(t, 2, conf.Attempts) |
| 51 | }) |
| 52 | |
| 53 | t.Run("attempts overridden", func(t *testing.T) { |
| 54 | cfgPath := writeResovConf(t, tmpDir, "nameserver 127.0.0.53\noptions attempts:3\n") |
| 55 | client := newMockClient() |
| 56 | |
| 57 | resolver := NewResolverWithClient(cfgPath, logger, period, client) |
| 58 | t.Cleanup(resolver.Stop) |
| 59 | |
| 60 | conf := resolver.getConfig() |
| 61 | require.Equal(t, []string{"127.0.0.53"}, conf.Servers) |
| 62 | require.Equal(t, 3, conf.Attempts) |
| 63 | }) |
| 64 | |
| 65 | t.Run("unknown settings ignored", func(t *testing.T) { |
| 66 | cfgPath := writeResovConf(t, tmpDir, "nameserver 127.0.0.53\noptions attempts:3\nfoo bar\noptions whatever:4\noptions single-request\n") |
| 67 | client := newMockClient() |
| 68 | |
| 69 | resolver := NewResolverWithClient(cfgPath, logger, period, client) |
| 70 | t.Cleanup(resolver.Stop) |
| 71 | |
| 72 | conf := resolver.getConfig() |
| 73 | require.Equal(t, []string{"127.0.0.53"}, conf.Servers) |
| 74 | require.Equal(t, 3, conf.Attempts) |
| 75 | }) |
| 76 | } |
| 77 | |
| 78 | func TestResolver_LookupSRV(t *testing.T) { |
| 79 | logger := log.NewNopLogger() |
nothing calls this directly
no test coverage detected