Skip to content

Commit 51cda04

Browse files
committed
fix: validate in docker in test mode
1 parent b8442a2 commit 51cda04

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

cmd/optimizer_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10-
11-
"github.com/natesales/pathvector/pkg/bird"
1210
)
1311

1412
func TestOptimizer(t *testing.T) {
15-
bird.Validate = bird.DockerValidate
16-
defer func() {
17-
bird.Validate = bird.LocalValidate
18-
}()
19-
2013
args := []string{
2114
"--verbose",
2215
}

pkg/bird/bird.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bird
33
import (
44
"bufio"
55
"bytes"
6+
"flag"
67
"fmt"
78
"io"
89
"net"
@@ -140,9 +141,15 @@ func RunCommand(command string, socket string) (string, string, error) {
140141
return resp, birdVersion, nil // nil error
141142
}
142143

143-
var Validate = LocalValidate
144+
func Validate(binary, cacheDir string) error {
145+
if flag.Lookup("test.v") != nil {
146+
return dockerValidate(binary, cacheDir)
147+
} else {
148+
return localValidate(binary, cacheDir)
149+
}
150+
}
144151

145-
func DockerValidate(_, _ string) error {
152+
func dockerValidate(_, _ string) error {
146153
args := []string{
147154
"docker", "exec",
148155
"pathvector-bird",
@@ -160,8 +167,8 @@ func DockerValidate(_, _ string) error {
160167
return nil
161168
}
162169

163-
// LocalValidate checks if the cached configuration is syntactically valid
164-
func LocalValidate(binary string, cacheDir string) error {
170+
// localValidate checks if the cached configuration is syntactically valid
171+
func localValidate(binary string, cacheDir string) error {
165172
log.Debugf("Validating BIRD config")
166173
var outBuf, errBuf bytes.Buffer
167174
birdCmd := exec.Command(binary, "-c", "bird.conf", "-p")

0 commit comments

Comments
 (0)