Skip to content

Commit 20f5e17

Browse files
committed
clean up some boolean checks
1 parent e41a518 commit 20f5e17

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

upnp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (d *IGD) checkForward(port uint16, proto string) (bool, error) {
7474

7575
if err != nil {
7676
// 714 "NoSuchEntryInArray" means that there is no such forwarding
77-
if contained := strings.Contains(err.Error(), "<errorCode>714</errorCode>"); contained == true {
77+
if strings.Contains(err.Error(), "<errorCode>714</errorCode>") {
7878
return false, nil
7979
}
8080
return false, err

upnp_test.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package upnp
22

33
import (
44
"context"
5-
"errors"
65
"sync"
76
"testing"
87
"time"
@@ -55,26 +54,18 @@ func TestIGD(t *testing.T) {
5554
}
5655
t.Log("Your external IP is:", ip)
5756

58-
// check that port 9001 is not forwarded
59-
res, err := d.IsForwardedTCP(9001)
60-
if err != nil {
61-
t.Fatal(err)
62-
} else if res == true {
63-
t.Fatal(errors.New("port 9001 is already forwarded"))
64-
}
65-
6657
// forward a port
6758
err = d.Forward(9001, "upnp test")
6859
if err != nil {
6960
t.Fatal(err)
7061
}
7162

7263
// check that port 9001 is now forwarded
73-
res, err = d.IsForwardedTCP(9001)
64+
forwarded, err := d.IsForwardedTCP(9001)
7465
if err != nil {
7566
t.Fatal(err)
76-
} else if res == false {
77-
t.Fatal(errors.New("port 9001 was not reported as forwarded"))
67+
} else if !forwarded {
68+
t.Fatal("port 9001 was not reported as forwarded")
7869
}
7970

8071
// un-forward a port
@@ -84,11 +75,11 @@ func TestIGD(t *testing.T) {
8475
}
8576

8677
// check that port 9001 is no longer forwarded
87-
res, err = d.IsForwardedTCP(9001)
78+
forwarded, err = d.IsForwardedTCP(9001)
8879
if err != nil {
8980
t.Fatal(err)
90-
} else if res == true {
91-
t.Fatal(errors.New("port 9001 is still forwarded"))
81+
} else if forwarded {
82+
t.Fatal("port 9001 should no longer be forwarded")
9283
}
9384

9485
// record router's location

0 commit comments

Comments
 (0)