resolvconf_unix_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // +build linux darwin
  2. package resolvconf
  3. import (
  4. "bytes"
  5. "io"
  6. "reflect"
  7. "testing"
  8. )
  9. const (
  10. testdata1 = `domain localdomain
  11. search localdomain
  12. nameserver 192.168.6.2`
  13. testdata2 = `#
  14. # macOS Notice
  15. #
  16. # This file is not consulted for DNS hostname resolution, address
  17. # resolution, or the DNS query routing mechanism used by most
  18. # processes on this system.
  19. #
  20. # To view the DNS configuration used by this system, use:
  21. # scutil --dns
  22. #
  23. # SEE ALSO
  24. # dns-sd(1), scutil(8)
  25. #
  26. # This file is automatically generated.
  27. #
  28. nameserver 10.23.194.202
  29. nameserver 10.23.194.203`
  30. )
  31. func Test_parse(t *testing.T) {
  32. type args struct {
  33. fp io.Reader
  34. }
  35. tests := []struct {
  36. name string
  37. args args
  38. want []string
  39. wantErr bool
  40. }{
  41. {
  42. name: "test1",
  43. args: args{
  44. bytes.NewBufferString(testdata1),
  45. },
  46. want: []string{"192.168.6.2"},
  47. },
  48. {
  49. name: "test2",
  50. args: args{
  51. bytes.NewBufferString(testdata2),
  52. },
  53. want: []string{"10.23.194.202", "10.23.194.203"},
  54. },
  55. }
  56. for _, tt := range tests {
  57. t.Run(tt.name, func(t *testing.T) {
  58. got, err := parse(tt.args.fp)
  59. if (err != nil) != tt.wantErr {
  60. t.Errorf("parse() error = %v, wantErr %v", err, tt.wantErr)
  61. return
  62. }
  63. if !reflect.DeepEqual(got, tt.want) {
  64. t.Errorf("parse() = %v, want %v", got, tt.want)
  65. }
  66. })
  67. }
  68. }