Skip to content

Commit 93bdf0d

Browse files
committed
refactor: cleanup
1 parent 263266e commit 93bdf0d

File tree

5 files changed

+19
-34
lines changed

5 files changed

+19
-34
lines changed

cmd/optimizer_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"path/filepath"
66
"strings"
77
"testing"
8+
9+
"github.com/stretchr/testify/assert"
810
)
911

1012
func TestOptimizer(t *testing.T) {
@@ -13,36 +15,27 @@ func TestOptimizer(t *testing.T) {
1315
"--dry-run",
1416
}
1517
files, err := filepath.Glob("../tests/probe-*.yml")
16-
if err != nil {
17-
t.Error(err)
18-
}
19-
if len(files) < 1 {
20-
t.Fatal("No test files found")
21-
}
18+
assert.Nil(t, err)
19+
assert.GreaterOrEqual(t, 1, len(files))
20+
2221
for _, testFile := range files {
2322
// Run pathvector to generate config first, so there is a config to modify
2423
rootCmd.SetArgs(append(args, []string{
2524
"--config", testFile,
2625
}...))
27-
if err := rootCmd.Execute(); err != nil {
28-
t.Error(err)
29-
}
26+
assert.Nil(t, rootCmd.Execute())
3027

3128
args = append(args, []string{
3229
"optimizer",
3330
"--config", testFile,
3431
}...)
3532
t.Logf("running probe integration with args %v", args)
3633
rootCmd.SetArgs(args)
37-
if err := rootCmd.Execute(); err != nil {
38-
t.Error(err)
39-
}
34+
assert.Nil(t, rootCmd.Execute())
4035

4136
// Check if local pref is lowered
4237
checkFile, err := os.ReadFile("test-cache/AS65510_EXAMPLE.conf")
43-
if err != nil {
44-
t.Error(err)
45-
}
38+
assert.Nil(t, err)
4639
if !strings.Contains(string(checkFile), "bgp_local_pref = 80; # pathvector:localpref") {
4740
t.Errorf("expected bgp_local_pref = 80 but not found in file")
4841
}

pkg/autodoc/documentation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package autodoc
22

33
import (
44
"testing"
5+
6+
"github.com/stretchr/testify/assert"
57
)
68

79
// TODO: lint the resulting markdown files
@@ -20,8 +22,6 @@ func TestSanitizeConfigName(t *testing.T) {
2022
}
2123
for _, tc := range testCases {
2224
out := sanitizeConfigName(tc.input)
23-
if out != tc.expected {
24-
t.Errorf("expected %s got %s", tc.expected, tc.input)
25-
}
25+
assert.Equal(t, tc.expected, out)
2626
}
2727
}

pkg/bird/bird_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ func TestBirdConn(t *testing.T) {
4545
buf := make([]byte, 1024)
4646
n, err := conn.Read(buf[:])
4747
assert.Nil(t, err)
48-
if string(buf[:n]) != "bird command test\n" {
49-
t.Errorf("expected 'bird command test' got %s", string(buf[:n]))
50-
}
48+
assert.Equal(t, "bird command test\n", string(buf[:n]))
5149

5250
_, err = conn.Write([]byte("0001 Fake BIRD response 2"))
5351
assert.Nil(t, err)

pkg/irr/irr_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package irr
22

33
import (
4-
"github.com/natesales/pathvector/pkg/util"
5-
"github.com/stretchr/testify/assert"
64
"reflect"
75
"testing"
86

7+
"github.com/stretchr/testify/assert"
8+
99
"github.com/natesales/pathvector/pkg/config"
10+
"github.com/natesales/pathvector/pkg/util"
1011
)
1112

1213
const irrQueryTimeout = 10
@@ -31,7 +32,7 @@ func TestGetIRRPrefixSet(t *testing.T) {
3132
t.Errorf("as-set %s family %d should error but didn't", tc.asSet, tc.family)
3233
}
3334
if err == nil && !reflect.DeepEqual(out, tc.expectedOutput) {
34-
t.Errorf("as-set %s family %d failed. expected '%s' got '%s'", tc.asSet, tc.family, tc.expectedOutput, out)
35+
assert.Equalf(t, tc.expectedOutput, out, "as-set %s family %d failed. expected '%s' got '%s'", tc.asSet, tc.family, tc.expectedOutput, out)
3536
}
3637
}
3738
}
@@ -57,12 +58,8 @@ func TestBuildIRRPrefixSet(t *testing.T) {
5758
} else if err == nil && tc.shouldError {
5859
t.Errorf("as-set %s should error but didn't", tc.asSet)
5960
}
60-
if !reflect.DeepEqual(tc.prefixSet4, *peer.PrefixSet4) {
61-
t.Errorf("as-set %s IPv4 prefix set expected %v got %v", tc.asSet, tc.prefixSet4, peer.PrefixSet4)
62-
}
63-
if !reflect.DeepEqual(tc.prefixSet6, *peer.PrefixSet6) {
64-
t.Errorf("as-set %s IPv6 prefix set expected %v got %v", tc.asSet, tc.prefixSet6, peer.PrefixSet6)
65-
}
61+
assert.Equal(t, tc.prefixSet4, *peer.PrefixSet4)
62+
assert.Equal(t, tc.prefixSet6, *peer.PrefixSet6)
6663
}
6764
}
6865

pkg/peeringdb/peeringdb_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ func TestSanitizeASSet(t *testing.T) {
9191
{"RADB::AS-HURRICANE RADB::AS-HURRICANEV6", "AS-HURRICANE"},
9292
}
9393
for _, tc := range testCases {
94-
out := sanitizeASSet(tc.asSet)
95-
if out != tc.expected {
96-
t.Errorf("expected %s got %s", tc.expected, out)
97-
}
94+
assert.Equal(t, tc.expected, sanitizeASSet(tc.asSet))
9895
}
9996
}

0 commit comments

Comments
 (0)