Skip to content

Commit

Permalink
fix: validate in docker in test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 15, 2025
1 parent b8442a2 commit 51cda04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
7 changes: 0 additions & 7 deletions cmd/optimizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/natesales/pathvector/pkg/bird"
)

func TestOptimizer(t *testing.T) {
bird.Validate = bird.DockerValidate
defer func() {
bird.Validate = bird.LocalValidate
}()

args := []string{
"--verbose",
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/bird/bird.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bird
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -140,9 +141,15 @@ func RunCommand(command string, socket string) (string, string, error) {
return resp, birdVersion, nil // nil error
}

var Validate = LocalValidate
func Validate(binary, cacheDir string) error {
if flag.Lookup("test.v") != nil {
return dockerValidate(binary, cacheDir)
} else {
return localValidate(binary, cacheDir)
}
}

func DockerValidate(_, _ string) error {
func dockerValidate(_, _ string) error {
args := []string{
"docker", "exec",
"pathvector-bird",
Expand All @@ -160,8 +167,8 @@ func DockerValidate(_, _ string) error {
return nil
}

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

0 comments on commit 51cda04

Please sign in to comment.