Skip to content

Commit

Permalink
refactor: cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Sep 2, 2024
1 parent 0d7d3d3 commit 63557f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 51 deletions.
50 changes: 13 additions & 37 deletions pkg/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,46 +247,22 @@ peers:

for peerName, peerData := range globalConfig.Peers {
if peerName == "Upstream 1" {
if *peerData.ASN != 65510 {
t.Errorf("peer %s expected ASN 65510 got %d", peerName, *peerData.ASN)
}
if *peerData.LocalPref != 90 {
t.Errorf("peer %s expected local-pref 90 got %d", peerName, *peerData.LocalPref)
}
if *peerData.FilterIRR != false {
t.Errorf("peer %s expected filter-irr false got %v", peerName, *peerData.FilterIRR)
}
if *peerData.FilterRPKI != true {
t.Errorf("peer %s expected filter-rpki true got %v", peerName, *peerData.FilterIRR)
}
assert.Equal(t, 65510, *peerData.ASN)
assert.Equal(t, 90, *peerData.LocalPref)
assert.False(t, *peerData.FilterIRR)
assert.True(t, *peerData.FilterRPKI)
} else if peerName == "Upstream 2" {
if *peerData.ASN != 65520 {
t.Errorf("peer %s expected ASN 65520 got %d", peerName, *peerData.ASN)
}
if *peerData.LocalPref != 90 {
t.Errorf("peer %s expected local-pref 90 got %d", peerName, *peerData.LocalPref)
}
if *peerData.FilterIRR != true {
t.Errorf("peer %s expected filter-irr true got %v", peerName, *peerData.FilterIRR)
}
if *peerData.FilterRPKI != true {
t.Errorf("peer %s expected filter-rpki true got %v", peerName, *peerData.FilterIRR)
}
assert.Equal(t, 65520, *peerData.ASN)
assert.Equal(t, 90, *peerData.LocalPref)
assert.True(t, *peerData.FilterIRR)
assert.True(t, *peerData.FilterRPKI)
} else if peerName == "Upstream 3" {
if *peerData.ASN != 65530 {
t.Errorf("peer %s expected ASN 65530 got %d", peerName, *peerData.ASN)
}
if *peerData.LocalPref != 2 {
t.Errorf("peer %s expected local-pref 2 got %d", peerName, *peerData.LocalPref)
}
if *peerData.FilterIRR != false {
t.Errorf("peer %s expected filter-irr false got %v", peerName, *peerData.FilterIRR)
}
if *peerData.FilterRPKI != true {
t.Errorf("peer %s expected filter-rpki true got %v", peerName, *peerData.FilterIRR)
}
assert.Equal(t, 65530, *peerData.ASN)
assert.Equal(t, 2, *peerData.LocalPref)
assert.False(t, *peerData.FilterIRR)
assert.True(t, *peerData.FilterRPKI)
} else {
t.Errorf("")
t.Errorf("unexpected peer %s", peerName)
}
}
}
20 changes: 6 additions & 14 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ func TestMoveFile(t *testing.T) {
inputString := "Test File"

//nolint:golint,gosec
if err := os.WriteFile("test-cache/source.txt", []byte(inputString), 0644); err != nil {
t.Error(err)
}
assert.Nil(t, os.WriteFile("test-cache/source.txt", []byte(inputString), 0644))

if err := MoveFile("test-cache/source.txt", "test-cache/dest.txt"); err != nil {
t.Error(err)
}
assert.Nil(t, MoveFile("test-cache/source.txt", "test-cache/dest.txt"))

if _, err := os.Stat("test-cache/dest.txt"); os.IsNotExist(err) {
t.Errorf("file text-cache/dest.txt doesn't exist but should")
Expand All @@ -69,15 +65,11 @@ func TestMoveFile(t *testing.T) {
t.Errorf("file text-cache/source.txt exists but shouldn't")
}

if contents, err := os.ReadFile("test-cache/dest.txt"); err != nil {
if string(contents) != inputString {
t.Errorf("expected %s got %s", inputString, contents)
}
}
contents, err := os.ReadFile("test-cache/dest.txt")
assert.Nil(t, err)
assert.Equal(t, inputString, string(contents))

if err := os.Remove("test-cache/dest.txt"); err != nil {
t.Error(err)
}
assert.Nil(t, os.Remove("test-cache/dest.txt"))
}

func TestPrintTable(t *testing.T) {
Expand Down

0 comments on commit 63557f7

Please sign in to comment.