Skip to content

Commit

Permalink
chore: rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf-joe committed May 9, 2020
1 parent f2f8c0b commit 100d6a1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions cmd/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/janeczku/go-ipset/ipset"
"github.com/stretchr/testify/assert"
"github.com/wolf-joe/ts-dns/cache"
"github.com/wolf-joe/ts-dns/core/mocker"
mock "github.com/wolf-joe/ts-dns/core/mocker"
"github.com/wolf-joe/ts-dns/hosts"
"github.com/wolf-joe/ts-dns/matcher"
"os"
Expand All @@ -22,7 +22,7 @@ func TestQueryLog(t *testing.T) {
assert.NotNil(t, logger)
assert.Nil(t, err)

mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()

logConf.File = "aaa"
Expand All @@ -39,7 +39,7 @@ func TestQueryLog(t *testing.T) {
}

func TestGroup(t *testing.T) {
mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()

group := Group{}
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestGroup(t *testing.T) {
}

func TestConf(t *testing.T) {
mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()

conf := &Conf{}
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestConf(t *testing.T) {
}

func TestNewHandler(t *testing.T) {
mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()

mocker.FuncSeq(toml.DecodeFile, []gomonkey.Params{
Expand Down
8 changes: 4 additions & 4 deletions inbound/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"github.com/wolf-joe/ts-dns/cache"
"github.com/wolf-joe/ts-dns/core/mocker"
mock "github.com/wolf-joe/ts-dns/core/mocker"
"github.com/wolf-joe/ts-dns/hosts"
"github.com/wolf-joe/ts-dns/matcher"
"github.com/wolf-joe/ts-dns/outbound"
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestHandler_Resolve(t *testing.T) {
callers := []outbound.Caller{caller1, caller2, &outbound.DNSCaller{}}
handler.Groups = map[string]*Group{"clean": {Callers: callers}}

mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()
// 测试Resolve
mocker.MethodSeq(caller2, "Resolve", []gomonkey.Params{
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestHandler(t *testing.T) {

req.SetQuestion("ip.cn.", dns.TypeA)

mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()

// 测试HitHosts
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestGroup(t *testing.T) {
callers := []outbound.Caller{&outbound.DNSCaller{}}
group := &Group{Callers: callers, Matcher: matcher.NewABPByText(""), IPSet: &ipset.IPSet{}}

mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()

ipv4 := net.IPv4(1, 1, 1, 1)
Expand Down
4 changes: 2 additions & 2 deletions inbound/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/sparrc/go-ping"
"github.com/stretchr/testify/assert"
"github.com/wolf-joe/ts-dns/cache"
"github.com/wolf-joe/ts-dns/core/mocker"
mock "github.com/wolf-joe/ts-dns/core/mocker"
"net"
"testing"
)
Expand All @@ -19,7 +19,7 @@ func TestTools(t *testing.T) {

assert.True(t, pingRtt("", -1) > maxRtt)
assert.True(t, pingRtt("111", -1) > maxRtt)
mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()
mocker.MethodSeq(&ping.Pinger{}, "Statistics", []gomonkey.Params{
{&ping.Statistics{PacketsRecv: 1, AvgRtt: maxRtt - 1}},
Expand Down
32 changes: 16 additions & 16 deletions outbound/caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package outbound

import (
"fmt"
mock "github.com/agiledragon/gomonkey"
"github.com/agiledragon/gomonkey"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"github.com/wolf-joe/ts-dns/core/mocker"
mock "github.com/wolf-joe/ts-dns/core/mocker"
"golang.org/x/net/proxy"
"io/ioutil"
"net"
Expand All @@ -26,20 +26,20 @@ func assertSuccess(t *testing.T, val *dns.Msg, err error) {
assert.Nil(t, err)
}

func MockMethodSeq(target interface{}, methodName string, outputs []mock.Params) *mock.Patches {
var cells []mock.OutputCell
func MockMethodSeq(target interface{}, methodName string, outputs []gomonkey.Params) *gomonkey.Patches {
var cells []gomonkey.OutputCell
for _, output := range outputs {
cells = append(cells, mock.OutputCell{Values: output})
cells = append(cells, gomonkey.OutputCell{Values: output})
}
return mock.ApplyMethodSeq(reflect.TypeOf(target), methodName, cells)
return gomonkey.ApplyMethodSeq(reflect.TypeOf(target), methodName, cells)
}

func TestDNSCaller(t *testing.T) {
req := &dns.Msg{}

caller := NewDNSCaller("", "", nil)
// 不使用代理,mock掉Exchange
p := MockMethodSeq(caller.client, "Exchange", []mock.Params{
p := MockMethodSeq(caller.client, "Exchange", []gomonkey.Params{
{nil, time.Second, fmt.Errorf("err")},
{&dns.Msg{}, time.Second, nil},
})
Expand All @@ -52,14 +52,14 @@ func TestDNSCaller(t *testing.T) {

caller = NewDoTCaller("", "", dialer)
// 使用代理,mock掉Dial、WriteMsg、ReadMsg
p1 := MockMethodSeq(caller.proxy, "Dial", []mock.Params{
p1 := MockMethodSeq(caller.proxy, "Dial", []gomonkey.Params{
{nil, fmt.Errorf("err")},
{&net.TCPConn{}, nil}, {&net.TCPConn{}, nil}, {&net.TCPConn{}, nil},
})
p2 := MockMethodSeq(caller.conn, "WriteMsg", []mock.Params{
p2 := MockMethodSeq(caller.conn, "WriteMsg", []gomonkey.Params{
{fmt.Errorf("err")}, {nil}, {nil},
})
p3 := MockMethodSeq(caller.conn, "ReadMsg", []mock.Params{
p3 := MockMethodSeq(caller.conn, "ReadMsg", []gomonkey.Params{
{nil, fmt.Errorf("err")}, {&dns.Msg{}, nil},
})
defer func() { p.Reset(); p1.Reset(); p2.Reset(); p3.Reset() }()
Expand All @@ -78,7 +78,7 @@ func TestDNSCaller(t *testing.T) {
}

func TestDoHCaller(t *testing.T) {
mocker := mocker.Mocker{}
mocker := mock.Mocker{}
defer mocker.Reset()

req := &dns.Msg{}
Expand All @@ -101,7 +101,7 @@ func TestDoHCaller(t *testing.T) {
assert.NotNil(t, caller)
assert.Equal(t, caller.port, "80")
// 测试.Resolve
mocker.FuncSeq(net.LookupIP, []mock.Params{
mocker.FuncSeq(net.LookupIP, []gomonkey.Params{
{nil, fmt.Errorf("err")}, {[]net.IP{nil}, nil}, {[]net.IP{{1, 1, 1, 1}}, nil},
})
err = caller.Resolve() // LookupIP返回异常
Expand All @@ -120,20 +120,20 @@ func TestDoHCaller(t *testing.T) {
assert.NotNil(t, err)

caller.Servers = []string{"1.1.1.1"}
mocker.MethodSeq(req, "PackBuffer", []mock.Params{
mocker.MethodSeq(req, "PackBuffer", []gomonkey.Params{
{nil, fmt.Errorf("err")}, {[]byte{1}, nil}, {[]byte{1}, nil},
{[]byte{1}, nil}, {[]byte{1}, nil}, {[]byte{1}, nil},
})
mocker.FuncSeq(http.NewRequest, []mock.Params{
mocker.FuncSeq(http.NewRequest, []gomonkey.Params{
{nil, fmt.Errorf("err")}, {httpReq, nil}, {httpReq, nil},
{httpReq, nil}, {httpReq, nil},
})
mocker.MethodSeq(caller.client, "Do", []mock.Params{
mocker.MethodSeq(caller.client, "Do", []gomonkey.Params{
{nil, fmt.Errorf("err")}, {&http.Response{Body: &net.TCPConn{}}, nil},
{&http.Response{Body: &net.TCPConn{}}, nil},
{&http.Response{Body: &net.TCPConn{}}, nil},
})
mocker.FuncSeq(ioutil.ReadAll, []mock.Params{
mocker.FuncSeq(ioutil.ReadAll, []gomonkey.Params{
{nil, fmt.Errorf("err")}, {make([]byte, 1), nil},
{make([]byte, 12), nil},
})
Expand Down

0 comments on commit 100d6a1

Please sign in to comment.