/
config.go
106 lines (90 loc) · 2.51 KB
/
config.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2019 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package envtest
import (
"net"
"path/filepath"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/uber/jaeger-client-go"
"github.com/scionproto/scion/go/lib/daemon"
"github.com/scionproto/scion/go/lib/env"
)
func InitTest(general *env.General, metrics *env.Metrics,
tracing *env.Tracing, d *env.Daemon) {
if general != nil {
InitTestGeneral(general)
}
if metrics != nil {
InitTestMetrics(metrics)
}
if tracing != nil {
InitTestTracing(tracing)
}
if d != nil {
InitTestSCIOND(d)
}
}
func InitTestGeneral(cfg *env.General) {
cfg.ReconnectToDispatcher = true
}
func InitTestMetrics(cfg *env.Metrics) {}
func InitTestTracing(cfg *env.Tracing) {
cfg.Enabled = true
cfg.Debug = true
}
func InitTestSCIOND(cfg *env.Daemon) {
cfg.Address = "garbage"
}
func CheckTest(t *testing.T, general *env.General, metrics *env.Metrics,
tracing *env.Tracing, d *env.Daemon, id string) {
if general != nil {
CheckTestGeneral(t, general, id)
}
if metrics != nil {
CheckTestMetrics(t, metrics)
}
if tracing != nil {
CheckTestTracing(t, tracing)
}
if d != nil {
CheckTestSciond(t, d, id)
}
}
func CheckTestGeneral(t *testing.T, cfg *env.General, id string) {
assert.Equal(t, id, cfg.ID)
assert.Equal(t, "/share/conf", cfg.ConfigDir)
assert.Equal(t, filepath.Join(cfg.ConfigDir, env.TopologyFile), cfg.Topology())
assert.False(t, cfg.ReconnectToDispatcher)
}
func CheckTestMetrics(t *testing.T, cfg *env.Metrics) {
assert.Empty(t, cfg.Prometheus)
}
func CheckTestTracing(t *testing.T, cfg *env.Tracing) {
assert.False(t, cfg.Enabled)
assert.False(t, cfg.Debug)
assert.Equal(
t,
net.JoinHostPort(
jaeger.DefaultUDPSpanServerHost,
strconv.Itoa(jaeger.DefaultUDPSpanServerPort),
),
cfg.Agent,
)
}
func CheckTestSciond(t *testing.T, cfg *env.Daemon, id string) {
assert.Equal(t, daemon.DefaultAPIAddress, cfg.Address)
assert.Equal(t, env.SciondInitConnectPeriod, cfg.InitialConnectPeriod.Duration)
}