Skip to content

Commit

Permalink
Add support of external dns for check domains
Browse files Browse the repository at this point in the history
Close #68
  • Loading branch information
rekby committed May 25, 2019
1 parent 34f8ad3 commit 9bed484
Show file tree
Hide file tree
Showing 14 changed files with 1,314 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/a_main-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cmd/static/default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ BlackList = ""
#
WhiteList = ""

# Comma separated dns server, used for resolve ip:port address of domains while check it.
# if empty - use system dns resolver (usually include hosts file, cache, etc)
# if set - use direct dns queries for servers, without self cache.
# if set more, than one dns server - send queries in parallel to all servers.
# error results from part of servers - ignore. Need minimum one answer.
# if different dns servers return different ip addresses - all of them use for check
# Example: "8.8.8.8:53,1.1.1.1:53,77.88.8.8:53,[2a02:6b8::feed:0ff]:53,[2001:4860:4860::8888]:53"
Resolver = ""



[Listen]

# Bind addresses for TLS listeners
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ require (
github.com/golangci/golangci-lint v1.16.0 // indirect
github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0
github.com/maxatome/go-testdeep v1.0.8
github.com/miekg/dns v1.1.12
github.com/mitchellh/gox v1.0.1 // indirect
github.com/pelletier/go-toml v1.3.0 // indirect
github.com/pkg/errors v0.8.1
github.com/rekby/zapcontext v0.0.3
github.com/satori/go.uuid v1.2.0
go.uber.org/zap v1.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpe
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/maxatome/go-testdeep v1.0.8 h1:OORprsdGMEDRo1diHCQzxCAaZFWKlHDrBnPttC4wL8g=
github.com/maxatome/go-testdeep v1.0.8/go.mod h1:Vcp0RXXOMhUTw2S2HRmUIqHQpG2Oxz+HM/WSWK7yXto=
github.com/miekg/dns v1.1.12 h1:WMhc1ik4LNkTg8U9l3hI1LvxKmIL+f1+WV/SZtCbDDA=
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
Expand Down
242 changes: 242 additions & 0 deletions internal/dns/m_dns_client_mock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
package dns

// DO NOT EDIT!
// The code below was generated with http://github.com/gojuno/minimock (dev)

//go:generate minimock -i github.com/rekby/lets-proxy2/internal/dns.mDNSClient -o ./m_dns_client_mock_test.go

import (
"sync/atomic"
"time"

mdns "github.com/miekg/dns"

"github.com/gojuno/minimock"
)

// MDNSClientMock implements mDNSClient
type MDNSClientMock struct {
t minimock.Tester

funcExchange func(msg *mdns.Msg, address string) (r *mdns.Msg, rtt time.Duration, err error)
afterExchangeCounter uint64
beforeExchangeCounter uint64
ExchangeMock mMDNSClientMockExchange
}

// NewMDNSClientMock returns a mock for mDNSClient
func NewMDNSClientMock(t minimock.Tester) *MDNSClientMock {
m := &MDNSClientMock{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.ExchangeMock = mMDNSClientMockExchange{mock: m}

return m
}

type mMDNSClientMockExchange struct {
mock *MDNSClientMock
defaultExpectation *MDNSClientMockExchangeExpectation
expectations []*MDNSClientMockExchangeExpectation
}

// MDNSClientMockExchangeExpectation specifies expectation struct of the mDNSClient.Exchange
type MDNSClientMockExchangeExpectation struct {
mock *MDNSClientMock
params *MDNSClientMockExchangeParams
results *MDNSClientMockExchangeResults
Counter uint64
}

// MDNSClientMockExchangeParams contains parameters of the mDNSClient.Exchange
type MDNSClientMockExchangeParams struct {
msg *mdns.Msg
address string
}

// MDNSClientMockExchangeResults contains results of the mDNSClient.Exchange
type MDNSClientMockExchangeResults struct {
r *mdns.Msg
rtt time.Duration
err error
}

// Expect sets up expected params for mDNSClient.Exchange
func (m *mMDNSClientMockExchange) Expect(msg *mdns.Msg, address string) *mMDNSClientMockExchange {
if m.mock.funcExchange != nil {
m.mock.t.Fatalf("MDNSClientMock.Exchange mock is already set by Set")
}

if m.defaultExpectation == nil {
m.defaultExpectation = &MDNSClientMockExchangeExpectation{}
}

m.defaultExpectation.params = &MDNSClientMockExchangeParams{msg, address}
for _, e := range m.expectations {
if minimock.Equal(e.params, m.defaultExpectation.params) {
m.mock.t.Fatalf("Expectation set by When has same params: %#v", *m.defaultExpectation.params)
}
}

return m
}

// Return sets up results that will be returned by mDNSClient.Exchange
func (m *mMDNSClientMockExchange) Return(r *mdns.Msg, rtt time.Duration, err error) *MDNSClientMock {
if m.mock.funcExchange != nil {
m.mock.t.Fatalf("MDNSClientMock.Exchange mock is already set by Set")
}

if m.defaultExpectation == nil {
m.defaultExpectation = &MDNSClientMockExchangeExpectation{mock: m.mock}
}
m.defaultExpectation.results = &MDNSClientMockExchangeResults{r, rtt, err}
return m.mock
}

//Set uses given function f to mock the mDNSClient.Exchange method
func (m *mMDNSClientMockExchange) Set(f func(msg *mdns.Msg, address string) (r *mdns.Msg, rtt time.Duration, err error)) *MDNSClientMock {
if m.defaultExpectation != nil {
m.mock.t.Fatalf("Default expectation is already set for the mDNSClient.Exchange method")
}

if len(m.expectations) > 0 {
m.mock.t.Fatalf("Some expectations are already set for the mDNSClient.Exchange method")
}

m.mock.funcExchange = f
return m.mock
}

// When sets expectation for the mDNSClient.Exchange which will trigger the result defined by the following
// Then helper
func (m *mMDNSClientMockExchange) When(msg *mdns.Msg, address string) *MDNSClientMockExchangeExpectation {
if m.mock.funcExchange != nil {
m.mock.t.Fatalf("MDNSClientMock.Exchange mock is already set by Set")
}

expectation := &MDNSClientMockExchangeExpectation{
mock: m.mock,
params: &MDNSClientMockExchangeParams{msg, address},
}
m.expectations = append(m.expectations, expectation)
return expectation
}

// Then sets up mDNSClient.Exchange return parameters for the expectation previously defined by the When method
func (e *MDNSClientMockExchangeExpectation) Then(r *mdns.Msg, rtt time.Duration, err error) *MDNSClientMock {
e.results = &MDNSClientMockExchangeResults{r, rtt, err}
return e.mock
}

// Exchange implements mDNSClient
func (m *MDNSClientMock) Exchange(msg *mdns.Msg, address string) (r *mdns.Msg, rtt time.Duration, err error) {
atomic.AddUint64(&m.beforeExchangeCounter, 1)
defer atomic.AddUint64(&m.afterExchangeCounter, 1)

for _, e := range m.ExchangeMock.expectations {
if minimock.Equal(*e.params, MDNSClientMockExchangeParams{msg, address}) {
atomic.AddUint64(&e.Counter, 1)
return e.results.r, e.results.rtt, e.results.err
}
}

if m.ExchangeMock.defaultExpectation != nil {
atomic.AddUint64(&m.ExchangeMock.defaultExpectation.Counter, 1)
want := m.ExchangeMock.defaultExpectation.params
got := MDNSClientMockExchangeParams{msg, address}
if want != nil && !minimock.Equal(*want, got) {
m.t.Errorf("MDNSClientMock.Exchange got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}

results := m.ExchangeMock.defaultExpectation.results
if results == nil {
m.t.Fatal("No results are set for the MDNSClientMock.Exchange")
}
return (*results).r, (*results).rtt, (*results).err
}
if m.funcExchange != nil {
return m.funcExchange(msg, address)
}
m.t.Fatalf("Unexpected call to MDNSClientMock.Exchange. %v %v", msg, address)
return
}

// ExchangeAfterCounter returns a count of finished MDNSClientMock.Exchange invocations
func (m *MDNSClientMock) ExchangeAfterCounter() uint64 {
return atomic.LoadUint64(&m.afterExchangeCounter)
}

// ExchangeBeforeCounter returns a count of MDNSClientMock.Exchange invocations
func (m *MDNSClientMock) ExchangeBeforeCounter() uint64 {
return atomic.LoadUint64(&m.beforeExchangeCounter)
}

// MinimockExchangeDone returns true if the count of the Exchange invocations corresponds
// the number of defined expectations
func (m *MDNSClientMock) MinimockExchangeDone() bool {
for _, e := range m.ExchangeMock.expectations {
if atomic.LoadUint64(&e.Counter) < 1 {
return false
}
}

// if default expectation was set then invocations count should be greater than zero
if m.ExchangeMock.defaultExpectation != nil && atomic.LoadUint64(&m.afterExchangeCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcExchange != nil && atomic.LoadUint64(&m.afterExchangeCounter) < 1 {
return false
}
return true
}

// MinimockExchangeInspect logs each unmet expectation
func (m *MDNSClientMock) MinimockExchangeInspect() {
for _, e := range m.ExchangeMock.expectations {
if atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to MDNSClientMock.Exchange with params: %#v", *e.params)
}
}

// if default expectation was set then invocations count should be greater than zero
if m.ExchangeMock.defaultExpectation != nil && atomic.LoadUint64(&m.afterExchangeCounter) < 1 {
m.t.Errorf("Expected call to MDNSClientMock.Exchange with params: %#v", *m.ExchangeMock.defaultExpectation.params)
}
// if func was set then invocations count should be greater than zero
if m.funcExchange != nil && atomic.LoadUint64(&m.afterExchangeCounter) < 1 {
m.t.Error("Expected call to MDNSClientMock.Exchange")
}
}

// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *MDNSClientMock) MinimockFinish() {
if !m.minimockDone() {
m.MinimockExchangeInspect()
m.t.FailNow()
}
}

// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *MDNSClientMock) MinimockWait(timeout time.Duration) {
timeoutCh := time.After(timeout)
for {
if m.minimockDone() {
return
}
select {
case <-timeoutCh:
m.MinimockFinish()
return
case <-time.After(10 * time.Millisecond):
}
}
}

func (m *MDNSClientMock) minimockDone() bool {
done := true
return done &&
m.MinimockExchangeDone()
}
Loading

0 comments on commit 9bed484

Please sign in to comment.