add ports flag to k8scan

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle
2018-07-13 17:56:53 -04:00
parent 7a969264ab
commit 2d54ed719f
3 changed files with 114 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
package main
import "testing"
import (
"reflect"
"testing"
)
func TestARINResponse(t *testing.T) {
info, err := getIPInfo("104.40.92.107")
@@ -18,3 +21,41 @@ func TestARINResponse(t *testing.T) {
t.Fatalf("expected reference to be https://whois.arin.net/rest/org/MSFT, got %s", info.Net.Organization.Reference)
}
}
func TestParsePortRange(t *testing.T) {
testFuncs := []struct {
given string
expected intSlice
}{
{
given: "",
expected: intSlice{80, 443, 8001, 9001},
},
{
given: "80,443,9090",
expected: intSlice{80, 443, 9090},
},
{
given: "80-90",
expected: intSlice{80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90},
},
{
given: "22-24,80,8080-8083",
expected: intSlice{22, 23, 24, 80, 8080, 8081, 8082, 8083},
},
{
given: "80",
expected: intSlice{80},
},
}
for _, testFunc := range testFuncs {
i := intSlice{}
if err := i.Set(testFunc.given); err != nil {
t.Fatal(err)
}
if reflect.DeepEqual(testFunc.expected, i) {
t.Fatalf("expected: %#v\ngot: %#v", testFunc.expected, i)
}
}
}