Skip to content

Commit

Permalink
use error check from common test lib
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Nov 7, 2024
1 parent 24f2973 commit 7d5a7f6
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions cmd/metal-api/internal/metal/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/metal-stack/metal-lib/pkg/testcommon"
)

var (
Expand Down Expand Up @@ -511,8 +512,8 @@ func Test_mapPortName(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := mapPortName(tt.port, tt.sourceOS, tt.targetOS, tt.allLines)
if !errorsAreEqual(err, tt.wantErr) {
t.Errorf("MapPortName() error = %v, wantErr %v", err, tt.wantErr)
if diff := cmp.Diff(err, tt.wantErr, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("MapPortName() error diff: %s", diff)
return
}
if got != tt.want {
Expand Down Expand Up @@ -623,8 +624,8 @@ func Test_sonicPortNameToLine(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := sonicPortNameToLine(tt.port)
if !errorsAreEqual(err, tt.wantErr) {
t.Errorf("sonicPortNameToLine() error = %v, wantErr %v", err, tt.wantErr)
if diff := cmp.Diff(err, tt.wantErr, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("sonicPortNameToLine() error diff: %s", diff)
return
}
if got != tt.want {
Expand Down Expand Up @@ -708,8 +709,8 @@ func Test_cumulusPortNameToLine(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := cumulusPortNameToLine(tt.port)
if !errorsAreEqual(err, tt.wantErr) {
t.Errorf("cumulusPortNameToLine() error = %v, wantErr %v", err, tt.wantErr)
if diff := cmp.Diff(err, tt.wantErr, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("cumulusPortNameToLine() error diff: %s", diff)
return
}
if got != tt.want {
Expand Down Expand Up @@ -835,15 +836,3 @@ func TestConnectionMap_ByNicName(t *testing.T) {
})
}
}

func errorsAreEqual(err1, err2 error) bool {
if err1 == nil && err2 == nil {
return true
}

if err1 != nil && err2 == nil || err1 == nil && err2 != nil {
return false
}

return err1.Error() == err2.Error()
}

0 comments on commit 7d5a7f6

Please sign in to comment.