-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unit-tests and it pre-commit hook
- Loading branch information
1 parent
afa9fb3
commit 9b9cad6
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/sh | ||
|
||
go test -v ./... | ||
if [ $? -ne 0 ]; then | ||
echo "unit tests failed" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"github.com/docent-net/ipcalc-contains/subnet" | ||
) | ||
|
||
func TestSubnetContainsShouldFailUncrecognizedIPv4Network(t *testing.T) { | ||
args := []string{"aaa", "192.168.123.0/30"} | ||
|
||
if subnet.SubnetContains(args) != false { | ||
t.Errorf("Expected %s to fail CIDR verification, but it did succeed", args[0]) | ||
} | ||
} | ||
|
||
func TestSubnetContainsShouldFailUncrecognizedIPv4(t *testing.T) { | ||
args := []string{"192.168.1.0/20", "abc"} | ||
|
||
if subnet.SubnetContains(args) != false { | ||
t.Errorf("Expected %s to fail CIDR verification, but it did succeed", args[1]) | ||
} | ||
} | ||
|
||
func TestSubnetContainsNetworkShouldContainNetwork(t *testing.T) { | ||
args := []string{"192.168.0.0/20", "192.168.12.0/30"} | ||
|
||
if subnet.SubnetContains(args) != true { | ||
t.Errorf("Expected %s to contain %s, but it failed", args[0], args[1]) | ||
} | ||
} | ||
|
||
func TestSubnetContainsNetworkShouldNotContainNetwork(t *testing.T) { | ||
args := []string{"192.168.0.0/20", "192.168.128.0/30"} | ||
|
||
if subnet.SubnetContains(args) != false { | ||
t.Errorf("Expected %s to NOT contain %s, but it did", args[0], args[1]) | ||
} | ||
} | ||
|
||
func TestSubnetContainsNetworkShouldContainIPv4(t *testing.T) { | ||
args := []string{"192.168.0.0/20", "192.168.12.123"} | ||
|
||
if subnet.SubnetContains(args) != true { | ||
t.Errorf("Expected %s to contain %s, but it failed", args[0], args[1]) | ||
} | ||
} | ||
|
||
func TestSubnetContainsNetworkShouldNotContainIPv4(t *testing.T) { | ||
args := []string{"192.168.0.0/20", "10.0.0.12"} | ||
|
||
if subnet.SubnetContains(args) != false { | ||
t.Errorf("Expected %s to NOT contain %s, but it did", args[0], args[1]) | ||
} | ||
} |