/
test_utils.go
89 lines (75 loc) · 1.97 KB
/
test_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (C) 2020-2021, IrineSistiana
//
// This file is part of mosdns.
//
// mosdns is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// mosdns is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package handler
import (
"context"
"github.com/miekg/dns"
"time"
)
// Types and funcs in this file are for testing only
type DummyMatcherPlugin struct {
*BP
Matched bool
WantErr error
}
func (d *DummyMatcherPlugin) Match(_ context.Context, _ *Context) (matched bool, err error) {
return d.Matched, d.WantErr
}
type DummyExecutablePlugin struct {
*BP
Sleep time.Duration
WantR *dns.Msg
WantErr error
}
func (d *DummyExecutablePlugin) Exec(_ context.Context, qCtx *Context) (err error) {
if d.Sleep != 0 {
time.Sleep(d.Sleep)
}
if d.WantErr != nil {
return d.WantErr
}
if d.WantR != nil {
qCtx.SetResponse(d.WantR, ContextStatusResponded)
}
return nil
}
type DummyESExecutablePlugin struct {
*BP
Sleep time.Duration
WantR *dns.Msg
WantSkip bool
WantErr error
}
func (d *DummyESExecutablePlugin) ExecES(_ context.Context, qCtx *Context) (earlyStop bool, err error) {
if d.Sleep != 0 {
time.Sleep(d.Sleep)
}
if d.WantErr != nil {
return false, d.WantErr
}
if d.WantR != nil {
qCtx.SetResponse(d.WantR, ContextStatusResponded)
}
return d.WantSkip, nil
}
type DummyServicePlugin struct {
*BP
WantShutdownErr error
}
func (d *DummyServicePlugin) Shutdown() error {
return d.WantShutdownErr
}