Skip to content

Commit 6b33b43

Browse files
committed
tests added
1 parent 480aed9 commit 6b33b43

File tree

8 files changed

+101
-35
lines changed

8 files changed

+101
-35
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- master
8+
- v2
9+
pull_request:
10+
jobs:
11+
golangci:
12+
strategy:
13+
matrix:
14+
go-version: [1.16.x]
15+
os: [ubuntu-latest]
16+
name: lint
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v2
22+
with:
23+
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
24+
version: v1.39

.github/workflows/gotest.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on: [push, pull_request]
2+
name: Go tests
3+
jobs:
4+
test:
5+
strategy:
6+
matrix:
7+
go-version: [1.16.x]
8+
os: [ubuntu-latest, macos-latest]
9+
runs-on: ${{ matrix.os }}
10+
steps:
11+
- name: Install Go
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: ${{ matrix.go-version }}
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
- name: Test
18+
run: go test ./...

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ go 1.16
44

55
require (
66
github.com/buglloc/simplelog v0.0.0-20190311170333-2fbd6fd42b73
7+
github.com/fsnotify/fsnotify v1.4.9 // indirect
78
github.com/karlseguin/ccache v2.0.3+incompatible
89
github.com/karlseguin/expect v1.0.8 // indirect
10+
github.com/kr/text v0.2.0 // indirect
911
github.com/miekg/dns v1.1.42
1012
github.com/mitchellh/go-homedir v1.1.0
13+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
1114
github.com/spf13/cobra v1.1.3
1215
github.com/spf13/pflag v1.0.5
1316
github.com/spf13/viper v1.7.1
1417
github.com/stretchr/testify v1.7.0
1518
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
1619
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
20+
golang.org/x/text v0.3.5 // indirect
21+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1722
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
1823
)

go.sum

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
3434
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
3535
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
3636
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
37+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
3738
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3839
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3940
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4041
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
4142
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
4243
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
43-
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
4444
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
45+
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
46+
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
4547
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
4648
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
4749
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
@@ -111,11 +113,11 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
111113
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
112114
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
113115
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
114-
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
115116
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
116117
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
117-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
118118
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
119+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
120+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
119121
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
120122
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
121123
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
@@ -137,6 +139,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
137139
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
138140
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
139141
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
142+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
143+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
140144
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
141145
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
142146
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
@@ -264,6 +268,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
264268
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
265269
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
266270
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
271+
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
267272
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
268273
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g=
269274
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -272,8 +277,9 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
272277
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
273278
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
274279
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
275-
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
276280
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
281+
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
282+
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
277283
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
278284
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
279285
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -317,8 +323,9 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq
317323
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
318324
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
319325
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
320-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
321326
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
327+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
328+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
322329
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
323330
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
324331
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

pkg/handlers/parser/parser_test.go

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/buglloc/rip/v2/pkg/handlers/loop"
1818
"github.com/buglloc/rip/v2/pkg/handlers/parser"
1919
"github.com/buglloc/rip/v2/pkg/handlers/proxy"
20+
"github.com/buglloc/rip/v2/pkg/handlers/sticky"
2021
)
2122

2223
func init() {
@@ -114,24 +115,21 @@ func TestParser(t *testing.T) {
114115
},
115116
},
116117
{
117-
in: "1-1-1-1.4.2-2-2-2.4.3-3-3-3.4.l",
118+
in: "2-2-2-2.4.3-3-3-3.4.l",
118119
handlers: []handlers.Handler{
119120
&loop.Handler{
120-
Len: 3,
121-
Nested: []handlers.Handler{
121+
Nested: [2]handlers.Handler{
122122
&ipv4.Handler{IP: net.ParseIP("3.3.3.3").To4()},
123123
&ipv4.Handler{IP: net.ParseIP("2.2.2.2").To4()},
124-
&ipv4.Handler{IP: net.ParseIP("1.1.1.1").To4()},
125124
},
126125
},
127126
},
128127
},
129128
{
130-
in: "1-1-1-1.4-ttl-10s.2-2-2-2.4-cnt-1.3-3-3-3.4-cnt-2.l",
129+
in: "1-1-1-1.4-ttl-10s.2-2-2-2.4.loop-cnt-1.3-3-3-3.4-cnt-2.l",
131130
handlers: []handlers.Handler{
132131
&loop.Handler{
133-
Len: 3,
134-
Nested: []handlers.Handler{
132+
Nested: [2]handlers.Handler{
135133
&ipv4.Handler{
136134
IP: net.ParseIP("3.3.3.3").To4(),
137135
BaseHandler: handlers.BaseHandler{
@@ -142,8 +140,22 @@ func TestParser(t *testing.T) {
142140
},
143141
},
144142
},
145-
&ipv4.Handler{
146-
IP: net.ParseIP("2.2.2.2").To4(),
143+
&loop.Handler{
144+
Nested: [2]handlers.Handler{
145+
&ipv4.Handler{
146+
IP: net.ParseIP("2.2.2.2").To4(),
147+
},
148+
&ipv4.Handler{
149+
IP: net.ParseIP("1.1.1.1").To4(),
150+
BaseHandler: handlers.BaseHandler{
151+
Limiters: limiter.Limiters{
152+
&limiter.TTL{
153+
TTL: 10 * time.Second,
154+
},
155+
},
156+
},
157+
},
158+
},
147159
BaseHandler: handlers.BaseHandler{
148160
Limiters: limiter.Limiters{
149161
&limiter.Count{
@@ -152,8 +164,20 @@ func TestParser(t *testing.T) {
152164
},
153165
},
154166
},
167+
},
168+
},
169+
},
170+
},
171+
{
172+
in: "2-2-2-2.4-ttl-10s.3-3-3-3.s",
173+
handlers: []handlers.Handler{
174+
&sticky.Handler{
175+
Nested: [2]handlers.Handler{
176+
&ipv4.Handler{
177+
IP: net.ParseIP("3.3.3.3").To4(),
178+
},
155179
&ipv4.Handler{
156-
IP: net.ParseIP("1.1.1.1").To4(),
180+
IP: net.ParseIP("2.2.2.2").To4(),
157181
BaseHandler: handlers.BaseHandler{
158182
Limiters: limiter.Limiters{
159183
&limiter.TTL{
@@ -167,11 +191,10 @@ func TestParser(t *testing.T) {
167191
},
168192
},
169193
{
170-
in: "1-1-1-1.4-ttl-10s.2-2-2-2.3-3-3-3.s",
194+
in: "2-2-2-2.v4.3-3-3-3.v4.s",
171195
handlers: []handlers.Handler{
172-
&loop.Handler{
173-
Len: 3,
174-
Nested: []handlers.Handler{
196+
&sticky.Handler{
197+
Nested: [2]handlers.Handler{
175198
&ipv4.Handler{
176199
IP: net.ParseIP("3.3.3.3").To4(),
177200
},
@@ -185,16 +208,6 @@ func TestParser(t *testing.T) {
185208
},
186209
},
187210
},
188-
&ipv4.Handler{
189-
IP: net.ParseIP("1.1.1.1").To4(),
190-
BaseHandler: handlers.BaseHandler{
191-
Limiters: limiter.Limiters{
192-
&limiter.TTL{
193-
TTL: 10 * time.Second,
194-
},
195-
},
196-
},
197-
},
198211
},
199212
},
200213
},

pkg/obfustacor/obfuscator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func IPv4(ipStr string) []string {
1212
result := make([]string, 0)
1313
result = append(result, fmt.Sprintf(
1414
"%d",
15-
(ip[0]<<24)|(ip[1]<<16)|(ip[2]<<8)|ip[3],
15+
(int(ip[0])<<24)|(int(ip[1])<<16)|(int(ip[2])<<8)|int(ip[3]),
1616
))
1717
result = append(result, fmt.Sprintf(
1818
"%#x.%#x.%#x.%#x",
@@ -55,7 +55,7 @@ func IPv4(ipStr string) []string {
5555
ip[0], ip[1], ip[2], ip[3],
5656
))
5757

58-
decSuffix := (ip[1] << 16) | (ip[2] << 8) | ip[3]
58+
decSuffix := (int(ip[1]) << 16) | (int(ip[2]) << 8) | int(ip[3])
5959
result = append(result, fmt.Sprintf(
6060
"%010o.%d",
6161
ip[0], decSuffix,

pkg/resolver/cache.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func (c *Cache) Set(reqType uint16, domain string, ttl time.Duration, ip []net.I
3333
}
3434

3535
c.lruCache.Set(key, ip, ttl)
36-
return
3736
}
3837

3938
func makeKey(reqType uint16, domain string) string {

pkg/resolver/upstreams.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func ResolveIp(reqType uint16, name string) ([]net.IP, error) {
3333
var ipv4 []net.IP
3434
var ipv6 []net.IP
3535
for _, rr := range res.Answer {
36-
switch rr.(type) {
36+
switch v := rr.(type) {
3737
case *dns.A:
38-
ipv4 = append(ipv4, rr.(*dns.A).A)
38+
ipv4 = append(ipv4, v.A)
3939
case *dns.AAAA:
40-
ipv6 = append(ipv6, rr.(*dns.AAAA).AAAA)
40+
ipv6 = append(ipv6, v.AAAA)
4141
}
4242
}
4343

0 commit comments

Comments
 (0)